⬡ GraphQL Intermediate

How does error handling work in GraphQL?

Answer

GraphQL's error model is unique: the response can contain both data and errors simultaneously. The response is always HTTP 200 with a JSON body containing data and/or errors arrays. Partial success is common — if one resolver fails, GraphQL returns the error for that field but still resolves all other fields. Each error in the errors array has a message, locations, path, and optional extensions for machine-readable codes. For client-facing errors (validation, auth), throw domain-specific errors in resolvers with an extensions.code. Unexpected server errors should be masked with a generic message to avoid leaking implementation details.