Error response structure
GraphQL responses always include adata field and may include an errors field:
Error types
Validation errors
Occur when your query doesn’t match the schema:Authentication errors
Occur when authentication fails:Business logic errors
Occur when operations fail due to business rules:Handling errors in code
JavaScript/TypeScript example
Partial data
GraphQL may return partial data even when some fields fail:data and errors in your response handling.
Error extensions
Many errors include extension fields with additional context:Best practices
- Always check for errors - Never assume a query succeeded
- Handle errors gracefully - Show user-friendly error messages
- Log errors for debugging - Include error details in logs
- Use error codes - Check
extensions.codefor specific error types - Handle partial data - Some fields may be null even if query succeeds
Common error codes
UNAUTHENTICATED- Authentication requiredFORBIDDEN- Insufficient permissionsNOT_FOUND- Resource doesn’t existVALIDATION_ERROR- Input validation failedINTERNAL_ERROR- Server error