Blue's GraphQL API is built on Apollo Server, which provides a standardized approach to error handling. When errors occur during the processing of a GraphQL operation, Apollo Server returns a response containing an array of errors. Each error object in this array includes an 'extensions' field, which offers valuable details such as:
These error codes and additional information allow developers to efficiently diagnose and address issues in their GraphQL queries or mutations.
This is an example of what an error object looks like:
{
"errors": [
{
"message": "Cannot query field \"__typenam\" on type \"Query\".",
"locations": [
{
"line": 1,
"column": 2
}
],
"extensions": {
"code": "GRAPHQL_VALIDATION_FAILED",
"stacktrace": [
"GraphQLError: Cannot query field \"__typenam\" on type \"Query\".",
" at Object.Field (/my_project/node_modules/graphql/validation/rules/FieldsOnCorrectTypeRule.js:48:31)",
" ...additional lines..."
]
}
}
]
}
This is a non-exhaustive list of error codes that you may encounter.
Error Code | Description |
---|---|
GRAPHQL_PARSE_FAILED | The GraphQL operation string contains a syntax error. |
GRAPHQL_VALIDATION_FAILED | The GraphQL operation is not valid against the server's schema. |
BAD_USER_INPUT | The GraphQL operation includes an invalid value for a field argument. |
PERSISTED_QUERY_NOT_FOUND | A client sent the hash of a query string to execute via automatic persisted queries, but the query was not in the APQ cache. |
PERSISTED_QUERY_NOT_SUPPORTED | A client sent the hash of a query string to execute via automatic persisted queries, but the server has disabled APQ. |
OPERATION_RESOLUTION_FAILURE | The request was parsed successfully and is valid against the server's schema, but the server couldn't resolve which operation to run. This occurs when a request containing multiple named operations doesn't specify which operation to run (i.e., operationName), or if the named operation isn't included in the request. |
BAD_REQUEST | An error occurred before your server could attempt to parse the given GraphQL operation. |
INTERNAL_SERVER_ERROR | An unspecified error occurred. When Apollo Server formats an error in a response, it sets the code extension to this value if no other code is set. |