createIndex for documentAccount viewer

Hello,

I’m trying to set up filtering functionality for the documentAccount fields. However, when I attempted to compile my model, I got the “:heavy_multiplication_x: controllerDID is not indexable” error.

Here is my schema:

type Profile
    @createModel(accountRelation: SINGLE, description: "A Profile")
    @createIndex(fields: [{path: ["controllerDID"]}])
    {
        controllerDID: DID! @documentAccount
        name: String! @string(minLength: 1, maxLength: 100)
        bio: String @string(minLength: 1, maxLength: 300)
        avatar: CID
    }

Any ideas?

Hi,

The @documentAccount directive represents a view to the controller in the stream metadata, it’s not part of the stream contents that can be indexed using the @createIndex directive.

What is your use-case of wanting to index the controller please? If it’s to perform queries filtered by controller, it’s possible to make controller-centric queries such as:

query {
  # use the controller DID as id
  node(id: "did:pkh:...") {
    ...on CeramicAccount {
      # any field present in the CeramicAccount object
      profile {
        displayName
      }
    }
  }
}

Hey @paul , thank you for the clarification.

I am trying to filter profiles by multiple dids with a query like: where did in [“did:pkh:…”].
I even wish I could do this for the document’s ID.

I guess the best method right now is to retrieve them one by one, as you shared.

Thanks for describing the use-case.
Considering you know the individual DIDs and stream IDs, you can already load them all in a single GraphQL query, for example:

fragment AccountFragment on Node {
  ...on CeramicAccount {
    profile {
      displayName
    }
  }
}

fragment PostFragment on Node {
  ...on Post {
    title
    text
  }
}

query {
  account1: node(id: "did:pkh:123...") {
    ...AccountFragment
  }
  account2: node(id: "did:pkh:456...") {
    ...AccountFragment
  }
  post1: node(id: "k6...123") {
    ...PostFragment
  }
  post2: node(id: "k6...456") {
    ...PostFragment
  }
}

@seref if that’s useful, one thing we could easily do is adding a nodes(ids: [ID!]!): [Node]! entry point to the query, so you could do queries such as:

query {
  accounts: nodes(ids: ["did:pkh:123...", "did:pkh:456..."]) {
      ...on CeramicAccount {
      profile {
        displayName
      }
    }
  }
  posts: nodes(ids: ["k6...123", "k6...456"]) {
    ...on Post {
      title
      text
    }
  }
}

Would that help support your use-case please?

Wow, that would be super.

Great! I just merged a PR to add support for this (cf Add `nodes` entry point to GraphQL queries by PaulLeCam · Pull Request #168 · ceramicstudio/js-composedb · GitHub), so this should be available in the next patch release.

1 Like

You are the best. :rocket:

Hey @seref, I just published v0.5.1 of the packages that should support the nodes entry-point, can you let me know if it works for you when you have time to try it out please? Thanks!

1 Like

It works super!

3 Likes