Every field in GraphQL is nullable by default, so it may return null. An exclamation mark after the type, as in String!, makes the field non-nullable, which promises it will never be null.
The default exists because many things can fail in a networked service. A database can go down or a permission check can fail. A nullable field lets that one field come back as null while the rest of the response still arrives.
A non-nullable field trades that safety for a stronger promise. If its resolver fails or returns null, the null propagates to the nearest nullable parent field, which becomes null instead.
Lists combine both markers. [Post!]! means neither the list nor its items can be null, while [String] allows both to be null.
type User {
id: ID! # Required field
name: String! # Required field
email: String # Optional field (can be null)
age: Int # Optional field
posts: [Post!]! # Required array of required Posts
tags: [String] # Optional array of optional strings
}
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓