⬡ GraphQL
Beginner
What is the difference between ! (non-null) and nullable fields in GraphQL?
Answer
In GraphQL, by default, all fields are nullable — a field can return null if the value is absent. Adding ! makes a field non-null — the server guarantees it will never return null. If a non-null resolver throws or returns null, GraphQL propagates the null error up to the nearest nullable parent. Examples: name: String (may be null), name: String! (never null), tags: [String] (list may be null), tags: [String!] (list not null but items may be null), tags: [String]! (list not null, items may be null), tags: [String!]! (both list and items are non-null). Best practice: be conservative — mark fields non-null only when you truly guarantee non-null values, as changing non-null to nullable is a breaking change.