Build the mental model
Where REST expresses errors through HTTP status codes (404, 500), a GraphQL response returns HTTP 200 and carries a separate `errors` array alongside `data`. If one field fails but sibling fields can still resolve, GraphQL returns a partial response containing both data and errors. The error object's `extensions` can carry a custom `code` (such as `NOT_FOUND` or `UNAUTHENTICATED`) so clients can handle errors programmatically.
Connect it to a real scenario
Querying tutorial 999, which does not exist, causes the resolver to throw a `GraphQLError` with `extensions.code: 'NOT_FOUND'`. The response's `data.tutorial` is `null`, `errors[0].path` is `["tutorial"]`, and the frontend checks `error.extensions.code` to show a "Tutorial not found" UI.
Try the working example
{
"data": {
"tutorial": null
},
"errors": [
{
"message": "Tutorial 999 not found",
"path": ["tutorial"],
"extensions": {
"code": "NOT_FOUND"
}
}
]
}You can read a GraphQL error response and write handling logic based on `extensions.code`.5-minute try-it
Write the response JSON shape you'd expect when the `author` field's resolver throws a `GraphQLError` with `extensions.code: 'NOT_FOUND'`.
One important caution
Client code that only checks HTTP status can miss GraphQL errors entirely — an HTTP 200 response can still carry an `errors` array, so always check it.
Apollo Server — Handling GraphQL Errors — GraphQL