Skip to content

Define a set of GraphQL custom statuses similar to HTTP status codes

Successful GraphQL responses always return status 200 (even if there is a top-level error). This makes it impossible to customize the handling error logic on the frontend, for example, retrying a query when there is a request timeout. We need to extend our error responses with additional information about the nature of the error and add frontend handlers for all types of errors we have defined.

What could this extension look like? I believe the simplest migration strategy could be something like:

{
  "errors": [
    {
      "message": "Houston, we have a problem here",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [...],
      "extensions": {
        "http": {
          "code": "408"
        }
      }
    }
  ]
}

But we can also provide our own custom strings like

      "extensions": {
        "problem": "timeout"
      }

The main requirement is that all custom fields have their respective frontend handlers (ideally, on the level of Apollo Client custom link)

Edited by Natalia Tepluhina