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?
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 :)
Most helpful comment
It's common practice to use
200for all GraphQL requests. When errors happen, they're put in the"errors"key. Non-200response codes indicate that some issue occurred at the HTTP transport layer, not the GraphQL layer.See Graph.cool docs for a bit more background.