@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.


Argument Type Required Description




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


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.


Given the following GraphQL schema:

type User {
  name: String

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

The database indexes would be:

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

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!