Skip to main content
GraphQL provides a structured way to handle errors. Understanding error responses helps you build robust applications.

Error response structure

GraphQL responses always include a data 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:
Always check for both data and errors in your response handling.

Error extensions

Many errors include extension fields with additional context:

Best practices

  1. Always check for errors - Never assume a query succeeded
  2. Handle errors gracefully - Show user-friendly error messages
  3. Log errors for debugging - Include error details in logs
  4. Use error codes - Check extensions.code for specific error types
  5. Handle partial data - Some fields may be null even if query succeeds

Common error codes

  • UNAUTHENTICATED - Authentication required
  • FORBIDDEN - Insufficient permissions
  • NOT_FOUND - Resource doesn’t exist
  • VALIDATION_ERROR - Input validation failed
  • INTERNAL_ERROR - Server error