Q13: Why are fields in GraphQL nullable by default?
Fields in GraphQL are nullable by default to handle distributed system errors gracefully. If a database query fails or a microservice is down, a single nullable field can evaluate to null while returning partial data for all valid fields without crashing the entire query.
Null Bubbling
If a non-nullable (!) field returns null due to an error, that null value 'bubbles up' to the nearest parent nullable field.
Key Takeaways
- Default nullability facilitates partial data responses during partial service outages.
Knowledge Check
What happens if a non-nullable field returns null due to a runtime error?