createIndex for accountReference/DID fields

This question is related to the one asked by @serafettin.eth in this topic, but the problem persists if the DID in question is not the controller of the document.

Consider a simple model linking two users together:

type UserLink = 
  @createModel(accountRelation: LIST)
  @createIndex(fields: [{ path: "toUser" }]) # Not possible :(
  fromUser: DID! @documentAccount
  toUser: DID! @accountReference

Let’s say I want to query for all users that have linked to a particular user. Since DID’s aren’t model instances, afaik it is not possible to add a relational frield to them. Additionally, since we can’t create the index in the type above this type of filtering is not possible either:

query {
  userLinkIndex(filters: {where: {toUser: {equalTo: "did:pkh:xyz"}}}) {
  	edges {
      node {

Is there any way to get the incoming relations for a given DID?

@paul can you take a look at this?

I don’t think I understand the problem here, why is it not possible to create an index on the toUser field?

Huh, it indeed seems possible. I’m not sure what I did wrong initially, but it does seem to work and I can’t reproduce the errors I got :white_check_mark: Thanks!

EDIT: quite sure I wanted to use the @documentAccount field like in the linked topic, but for filtering in a deeper query where that DID is not the main subject. From that discussion I take it’s not possible? My guess is that it’s because that @documentAccount entry is a view and not actually part of the model?

A related follow-up though: is there a way of using @relationFrom views directly on DID/CeramicAccount nodes somehow?

Example: I want query for a specific node by DID and see the incoming UserLink entries (where it is the toUser). The outgoing is already there in the form of the built-in userLinkList that is automatically attached directly on the CeramicAccount. I’ve been trying to make this happen, but it only allows me to put views on models.

Consider the case where you have some type of user profile, and the owner has created a UserLink to some other user. I can’t show the outgoing links on the profile, but I can get to them indirectly by jumping to the owner (@documentAccount) and there query userLinkList.

There is however no way of showing the incoming links on a CeramicAccount because it doesn’t allow @relationFrom, not being a model. However, there is also no way of showing the incoming UserLinks on a separate profile model because it’s the DID that is the target so a @relationFrom will not match since they do not point to the profile but the account.

What’s the suggested way of dealing with this? Since the DIDs are valid StreamID entries in the model, it’s confusing that they cannot be used in the same way.

DIDs are not StreamIDs, they are completely different identifiers. DIDs represent accounts while StreamIDs represent unique streams (documents in ComposeDB).

If I understand correctly what you’re asking, you want to access from the CeramicAccount object the documents that reference the given account DID in one of their fields?
If so, I opened a PR to support this based on the @accountReference directive: Add inverse relations to CeramicAccount by PaulLeCam · Pull Request #182 · ceramicstudio/js-composedb · GitHub

Thanks for the clarification! I know DIDs are not streams, being able to use them in node(id: ...) queries seem to have mixed things up for a bit :slight_smile:

The PR is spot on, this is much appreciated Paul! :pray:

Great, thanks for confirming!