Require an output value
A field must always identify a resource.
GraphQL · Class
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.
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.
type!A non-null variant of the wrapped GraphQL type; it disallows null output values and represents required input values.
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.
A field must always identify a resource.
An operation cannot run without a caller-supplied identifier.
A collection should contain only present items or itself be present.
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.
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.
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.
ListNullable typesType modifiersArgumentsInput object fields