graphql-over-http icon indicating copy to clipboard operation
graphql-over-http copied to clipboard

Status codes 404 and 410

Open saerdnaer opened this issue 1 year ago • 1 comments

Just to clarify: What would be the correct behaviour for a root level resolver which did not find and matching records (404), or knows that the requested record is no longer available (410)?

https://github.com/graphql/graphql-over-http/blob/main/spec/GraphQLOverHTTP.md#applicationgraphql-responsejson

This section only applies when the response body is to use the application/graphql-response+json media type.

If the GraphQL response contains the {data} entry and it is not {null}, then the server MUST reply with a 2xx status code and SHOULD reply with 200 status code. …

If the GraphQL response contains the {data} entry and it is {null}, then the server SHOULD reply with a 2xx status code and it is RECOMMENDED it replies with 200 status code.

Note: Using 4xx and 5xx status codes in this situation is not recommended - since no GraphQL request error has occurred it is seen as a "partial response".

If the GraphQL response does not contain the {data} entry then the server MUST reply with a 4xx or 5xx status code as appropriate.

Note: The GraphQL specification indicates that the only situation in which the GraphQL response does not include the {data} entry is one in which the {errors} entry is populated.

So I either have to return

  • 200 { "data": null } or
  • 404 { "errors": [ {"message": "item could not be found"} ] } /
  • 410 { "errors": [ {"message": "item is no longer available"} ] } to conform to the specs?

saerdnaer avatar Dec 05 '22 23:12 saerdnaer