Pothos v4 is now available! 🎉Check out the full migration guide here

Pothos

Default nullability

By default, Fields and argument in Pothos ar Nullable. This default can be changed be overwritten by setting nullable: false 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, Pothos allows overwriting these defaults when setting up your SchemaBuilder. You will need to provide the new defaults in two 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.

// Create a Builder that makes output fields nullable by default
export const builder = new SchemaBuilder<{
  DefaultFieldNullability: false;
}>({
  defaultFieldNullability: false,
});
 
// Create a Builder that makes input fields and arguments required by default
export const builder = new SchemaBuilder<{
  DefaultInputFieldRequiredness: true;
}>({
  defaultInputFieldRequiredness: true,
});

On this page

No Headings