Graphql-ruby: why graphql returns "200 OK" response code for exceptions?

Created on 26 Nov 2017  路  4Comments  路  Source: rmosolgo/graphql-ruby

When i pass some unknown fields in a query(field that does not exist) or invalid variables (I mean server expecting an int value but i am passing a string value), why does it returns "200OK" as its status code in reponse?

Most helpful comment

It's common practice to use 200 for all GraphQL requests. When errors happen, they're put in the "errors" key. Non-200 response codes indicate that some issue occurred at the HTTP transport layer, not the GraphQL layer.

See Graph.cool docs for a bit more background.

All 4 comments

It's common practice to use 200 for all GraphQL requests. When errors happen, they're put in the "errors" key. Non-200 response codes indicate that some issue occurred at the HTTP transport layer, not the GraphQL layer.

See Graph.cool docs for a bit more background.

Is there a way to force other status code? Maybe for unauthorized?

graphql-ruby doesn't have any code relating to HTTP status codes. If you want to use a different error code, maybe you could inspect the returned hash's "errors" key.

Basicly your PC has to use extra resources to determine if there was an error in your response or not (it needs to parse/decode the whole body beacuse of it)

Moreover in Browsers dev tools -> Network tab, you see always 200 status :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jtippett picture jtippett  路  3Comments

rylanc picture rylanc  路  3Comments

theodorton picture theodorton  路  3Comments

jesster2k10 picture jesster2k10  路  3Comments

sayduck-daniel picture sayduck-daniel  路  3Comments