Q23: How does error handling work in GraphQL responses?
Unlike REST (which uses HTTP status codes like 404 or 500), GraphQL usually returns 200 OK with a payload containing a top-level errors array alongside partial data results.
Standard GraphQL Error Format
{
"data": { "user": null },
"errors": [
{
"message": "User not found",
"locations": [{ "line": 2, "column": 3 }],
"path": ["user"],
"extensions": { "code": "NOT_FOUND" }
}
]
}💡 The payload contains a path map, error classification, and exact location markers.
Key Takeaways
- GraphQL responses can simultaneously yield partial
dataand executionerrors. - Standard error objects include
message,locations,path, andextensions.
Knowledge Check
What is the conventional top-level key for metadata in a standard GraphQL error object?