GraphQL Schema Directives

This page provides an overview of the various GraphQL schema directives made available in neo4j-graphql.js. See the links in the table below for full documentation of each directive.

What Are GraphQL Schema Directives

GraphQL schema directives are a powerful feature of GraphQL that can be used in the type definitions of a GraphQL schema to indicate non-default logic and can be applied to either fields on types. Think of a schema directive as a way to indicate custom logic that should be executed on the GraphQL server.

In neo4j-graphql.js we use schema directives to:

  • help describe our data model (@relation, @id, @unique, @index)
  • implement custom logic in our GraphQL service (@cypher, @neo4j_ignore)
  • help implement authorization logic (@additionalLabel, @isAuthenticated, @hasRole, @hasScope)

Neo4j GraphQL Schema Directives

The following GraphQL schema directives are declared during the schema augmentation process and can be used in the type definitions passed to makeAugmentedSchema.

DirectiveArgumentsDescriptionNotes
@relationname, directionUsed to define relationship fields and types in the GraphQL schema.See Designing Your GraphQL Schema Guide
@idUsed on fields to (optionally) specify the field to be used as the ID for the type.See API Reference
@uniqueUsed on fields to (optionally) specify fields that should have a uniqueness constraint.See API Reference
@indexUsed on fields to indicate an index should be created on this field.See API Reference
@cypherstatementUsed to define custom logic using Cypher.See Defining Custom Logic, and Designing Your GraphQL Schema
@searchindexUsed on fields to set full-text search indexes.See API Reference
@neo4j_ignoreUsed to exclude fields or types from the Cypher query generation process. Use when implementing a custom resolver.See Defining Custom Logic
@additionalLabelslabelsUsed for adding additional node labels to types. Can be useful for multi-tenant scenarios where an additional node label is used per tenant.See GraphQL Authorization
@isAuthenticatedProtects fields and types by requiring a valid signed JWTSee GraphQL Authorization
@hasRolerolesProtects fields and types by limiting access to only requests with valid rolesSee GraphQL Authorization
@hasScopescopesProtects fields and types by limiting access to only requests with valid scopesSee GraphQL Authorization