Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

GraphQL · Class

GraphQLNonNull

GraphQLNonNull marks a GraphQL type as non-null using !. It guarantees a value for output fields and requires values for inputs, including arguments and input object fields.

How it works

GraphQLNonNull is represented in schema notation by placing ! after an underlying type, such as String!. It prevents null results for output fields and makes input arguments or input fields required; for lists, it can constrain either the list itself or its elements.

Syntax

type!

Returns

A non-null variant of the wrapped GraphQL type; it disallows null output values and represents required input values.

Key points

  • GraphQL types are nullable unless a type modifier changes that default.
  • Schema notation uses ! after the underlying type, for example String!.
  • Non-null input arguments and input fields must be provided by the caller.
  • A non-null type disallows null in the value it wraps.

Common mistakes

  • Returning null from a non-null output field causes an execution error rather than a normal nullable result.
  • A non-null input must be supplied and cannot explicitly receive null.

Example: Non-null fields and arguments

type Query {
  user(id: ID!): User!
}

type User {
  id: ID!
  name: String!
}

This schema requires the id argument and guarantees that user, id, and name are not null.

When to use it

Require an output value

A field must always identify a resource.

Require an argument

An operation cannot run without a caller-supplied identifier.

Constrain list nullability

A collection should contain only present items or itself be present.

Interview questions

QWhat does GraphQLNonNull do?

The exclamation mark creates a non-null type by wrapping an underlying type. For output fields, the server must not return null; for inputs, the value is required and null is rejected.

Follow-up: How does nullability apply to a list? A type such as [String!]! requires both the list and every element to be non-null.

QHow does non-null affect field execution?

A nullable output field can return null, while a non-null output field promises that it will not. If the resolver violates that promise, GraphQL reports an execution error.

Follow-up: What happens higher in the response tree? The nullability rules determine how the error propagates through enclosing fields, potentially making a nullable parent null.

QHow does non-null affect arguments?

For an input argument, non-null means the argument is required: callers cannot omit it or provide null. Nullable arguments remain optional by default.

Follow-up: Can a nullable variable be passed to a non-null argument? Generally no, because the variable type does not guarantee the required value.

  • List
  • Nullable types
  • Type modifiers
  • Arguments
  • Input object fields

Source: Schemas and Types - GraphQL. Checked 2026-10-15.