⬡ GraphQL Beginner

What is the difference between nullable and non-null types in GraphQL?

Answer

In GraphQL, every type is nullable by default — a field can return null if no data is available. Adding a ! suffix makes a type non-null, meaning the server guarantees the field will never be null. Example: name: String! guarantees a string is always returned, while name: String may return null. Non-null is used for required fields like id: ID!. If a non-null field resolver returns null at runtime, GraphQL treats it as an error and bubbles the null up to the nearest nullable parent, potentially nulling out entire subtrees — a behavior to design around carefully.