Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status codes 404 and 410 #234

Open
saerdnaer opened this issue Dec 5, 2022 · 1 comment
Open

Status codes 404 and 410 #234

saerdnaer opened this issue Dec 5, 2022 · 1 comment

Comments

@saerdnaer
Copy link

saerdnaer commented Dec 5, 2022

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?
@spawnia
Copy link
Member

spawnia commented Dec 6, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants