@index directive

Specifies the name of the index used to collate documents of the current type, instead of an automatically-created index name based on the field’s name.

Schema location

This directive is valid for any fields within a Query declaration within a GraphQL schema.

Arguments

Argument Type Required Description

name

String

Yes

The name for the database index to use for this GraphQL query field.

Description

The @index directive controls the name of the underlying database index for the annotated field. By default, the GraphQL API uses the name of the query field as the name of the index within the database.

When an index with the specified name already exists, the GraphQL API uses that index. If not, the GraphQL API creates the index using the specified name.

When your @index directive specifies the name of an existing index, if the index definition does not match your type, your queries may result in errors due to the shape of your type being incompatible with the index definition.

Example

Given the following GraphQL schema:

type User {
  name: String
}

type Query {
  allUsers: [User!] @index(name: "all_users")
}

The database indexes would be:

Paginate(Indexes())
{ data: [ Index("all_users") ] }

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!