Search⌘ K
AI Features

Schema with Lists and Non-Null

Explore how to apply list and non-null modifiers within GraphQL schemas to control data validation and response types. Understand the impact of these modifiers on queries and mutations to ensure precise API functionality.

The only types we can define in GraphQL are object, scalars, and enums. But when we use the non-null modifier in our query or fields, we can also register additional type modifiers that affect the validation of the values. Let’s look at an example:

Javascript (babel-node)
type Pizza {
id: Int!
pizza: String!
stock: Int!
toppings: [Topping!]!
}

Non-null modifier type

In the example above, pizza is a field with a String type. If we mark it as non-null by adding an exclamation mark (!) after the type name, our server will return a non-null value. If, for some ...