Type configuration

This is the documentation of the GraphQL Library version 6. For the long-term support (LTS) version 5, refer to GraphQL Library version 5 LTS.

When representing a Neo4j node, a GraphQL Object Type produces multiple operation fields in the query, mutation, and subscription types. For example:

type Movie @node {
    title: String
    length: Int
}

From these type definitions, the library generates the following operation fields:

Query:

  • movies

  • moviesAggregate

  • moviesConnection

Mutation:

  • createMovies

  • deleteMovies

  • updateMovies

Subscription:

  • movieCreated

  • movieUpdated

  • movieDeleted .

This page describes how to reduce the operation fields produced using the directives @query, @mutation, and @subscription.

@query

This directive is used to limit the availability of query operations in the library.

Definition

directive @query(read: Boolean! = true, aggregate: Boolean! = false) on OBJECT | SCHEMA | INTERFACE | UNION

Usage

Disable movies and moviesConnection operations
type Movie @node @query(read: false, aggregate: true) {
    title: String
    length: Int
}
Disable moviesAggregate operations
type Movie @node @query(read: true, aggregate: false)  {
    title: String
    length: Int
}

@mutation

This directive is used to limit the availability of mutation operations in the library.

Definition

enum MutationFields {
    CREATE
    UPDATE
    DELETE
}

directive @mutation(operations: [MutationFields!]! = [CREATE, UPDATE, DELETE]) on OBJECT | SCHEMA

Usage

Disable Create, Delete, and Update operations for Movie
type Movie @node @mutation(operations: []) {
    title: String
    length: Int
}
Enable only Create operations for Movie
type Movie @node @mutation(operations: [CREATE]) {
    title: String
    length: Int
}

@subscription

This directive is used to limit subscription operations in the library.

Definition

enum SubscriptionFields {
    CREATED
    UPDATED
    DELETED
}

directive @subscription(events: [SubscriptionFields!]! = [CREATED, UPDATED, DELETE]) on OBJECT | SCHEMA

Usage

Disable subscriptions for Movie
type Movie @node @subscription(events: [])  {
    title: String
    length: Int
}
Enable only movieCreated subscription for Movie
type Movie @node @subscription(events: [CREATED]) {
    title: String
    length: Int
}

@default

When generating the input type for the create mutation, the value specified in this directive is used as the default for the field.

Definition

"""Int | Float | String | Boolean | ID | DateTime | Enum"""
scalar Scalar

"""Instructs @neo4j/graphql to set the specified value as the default value in the CreateInput type for the object type in which this directive is used."""
directive @default(
    """The default value to use. Must be a scalar type and must match the type of the field with which this directive decorates."""
    value: Scalar!,
) on FIELD_DEFINITION

Usage

@default may be used with enums. When setting the default value for an enum field, it must be one of the enumerated enum values:

enum Location {
    HERE
    THERE
    EVERYWHERE
}

type SomeType @node {
    firstLocation: Location! @default(value: HERE) # valid usage
    secondLocation: Location! @default(value: ELSEWHERE) # invalid usage, will throw an error
}

@plural

Definition

"""
Instructs @neo4j/graphql to use the given value as the plural of the type name
"""
directive @plural(
  """The value to use as the plural of the type name."""
  value: String!
) on OBJECT | INTERFACE | UNION

Usage

This directive redefines how to compose the plural of the type for the generated operations. This is particularly useful for types that are not correctly pluralized or are non-English words. Take this type definition as an example:

type Tech @plural(value: "Techs") @node {
  name: String
}

This way, instead of the wrongly generated teches, the type is properly written as techs:

{
  techs {
    title
  }
}

The same is applied to other operations such as createTechs. However, keep in mind that database labels are not changed with this directive.