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
@mutation
@subscription
This directive is used to limit subscription operations in the library.
@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 {
firstLocation: Location! @default(value: HERE) # valid usage
secondLocation: Location! @default(value: ELSEWHERE) # invalid usage, will throw an error
}
@plural
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") {
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.