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