@index directive does not work with @resolver directive

The current documentation specifies that the @index directive is added at the end of a Query function in the GraphQL schema. However, I can only use the @index directive if I get rid of the @resolver directive. I am confused by this as I used the @resolver directive to indicate to GraphQL that my UDF was paginated. The goal is to get all my documents back and paginate them. An index to get all the documents back is what I need in this use case, however, I thought I also needed a UDF that incorporated pagination. Is the @index directive supposed to replace the need for a UDF here and just be defined within Query block? If that’s the case, its confusing to build an index for a Query function if it doesn’t actually point back to a Query function. Am I missing something here? Or does GraphQL know behind the hood that the @index directive also points to a resolver? If so, how would I go about pagination in this case?

It seems like the only solution I know is to define the index separately and use @resolver(paginated: true) in my schema. But this feels like it shouldn’t be the case and I should just be able to define the @index and @resolver directive on the same line.

The @index directive creates an Index based on the types used. If you simply want to query an index (equivalent to Paginate(Match(Index("my_index")))) then use @index. @index fields are paginated without additional work, but they are limited to simple index queries.

If you want to do some extra compute (maybe sorting, using multiple indexes, or manipulating the data), then use @resolver.

Does post help? Understanding fauna auto-generation from schema

I’m not sure what you mean.

If you do not provide any directive, then Fauna assumes it is @index. For example

type Query {
  # this
  thingsByColor(color: String!): [Thing]
  
  # is equivalent to:
  thingsByColor(color: String!): [Thing] @index(name: "thingsByColor")
}
1 Like

Okay that makes sense. I guess the confusion came from calling the index in graphQL and using pagination with it as my UDF is no longer a resolver

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.