GiraphQL
Search…
Changing Default Nullability
By Default GiraphQL makes fields on output types Non-Nullable, and Arguments and Fields on InputObjects optional. These defaults can be overwritten by either setting setting nullable: true in the options for output fields and by setting required: true for input fields or arguments.
These defaults may not be the right choice for every application, and changing them on every field can be a pain. Instead, GiraphQL allows overwriting these defaults when setting up your SchemaBuilder. You will need to provide the new defaults in 2 places:
    1.
    In the type parameter for the builder, which enables the type checking to work with your new
    settings
    2.
    In the Builder options, so that the correct schema is built at run time.
1
// Create a Builder that makes output fields nullable by default
2
export const builder = new SchemaBuilder<{
3
DefaultFieldNullability: true;
4
}>({
5
defaultFieldNullability: true,
6
});
7
8
// Create a Builder that makes input fields and arguments required by default
9
export const builder = new SchemaBuilder<{
10
DefaultInputFieldRequiredness: true;
11
}>({
12
defaultInputFieldRequiredness: true,
13
});
Copied!
Last modified 6mo ago
Copy link