Status codes 404 and 410
saerdnaer opened this issue · 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)?
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?
The GraphQL spec tells you what shape your returned result must take. Inclusion of an error depends on the field being nullable.
Following from that, this spec tells you what the status code should be. Basically, as long as your server produced a proper GraphQL response, always 200.