Type configuration

When representing a Neo4j node, a GraphQL Object Type produces multiple operation fields in the Query, Mutation, and Subscription types. For example:

type Movie {
    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

Aggregations are no longer generated by default in the 4.0.0 version of the library. See Updated directives for more information.

Usage

Disable movies and moviesConnection operations
type Movie @query(read: false, aggregate: true) {
    title: String
    length: Int
}
Disable moviesAggregate operations
type Movie @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 @mutation(operations: []) {
    title: String
    length: Int
}
Enable only Create operations for Movie
type Movie @mutation(operations: [CREATE]) {
    title: String
    length: Int
}

@subscription

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

Definition

enum SubscriptionFields {
    CREATE
    UPDATE
    DELETE
    CREATE_RELATIONSHIP
    DELETE_RELATIONSHIP
}

directive @subscription(operations: [SubscriptionFields!]! = [CREATE, UPDATE, DELETE, CREATE_RELATIONSHIP, DELETE_RELATIONSHIP]) on OBJECT | SCHEMA

Usage

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