HTTP Status 200 when a mutation fails
See original GitHub issueI’m using graphene.contrib.django
If I raise an exception inside a mutation’s mutate_and_get_payload()
(e.g. because of a failed data validation), the resulting http response’s code is 200 (OK). I’d expect 400 (Bad request).
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
API returns errors with status 200? - monday Community Forum
While a 200 status on the ColumnValueException means: “The request was parsed successfully, but there was an issue with it. Your column values ......
Read more >Resolving a mutation with errors | Lift-off IV - Apollo GraphQL
When an error occurs, Apollo Server attaches an extensions field to that error that contains relevant error details.
Read more >Override GraphQL Default Status Code(200) With Different ...
By default GraphQL sends 200 status code even though its an error and error details comes as part of the error section in...
Read more >200 OK - HTTP - MDN Web Docs
The HTTP 200 OK success status response code indicates that the request has succeeded. A 200 response is cacheable by default.
Read more >Hygraph error codes
Errors ; 200, OK - Successful response ; 400, Bad request - Typically due to invalid query arguments ; 401, Unauthorized - Usually...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As far as I can tell from the GraphQL spec there is no discussion of http response codes at all. The status codes of HTTP are strongly tied to rest principles. It’s not clear to me whether GraphQL APIs should distinguish between 2XX and 4XX status codes.
Most notably, you can batch multiple mutations into the same request to the server. If one successfully creates a resource (201), one mutates a resource (200), one fails validation (400) and another the target object does not exists (404), what should the return value from the API be?
At the moment, GraphQL APIs seem to err on the side of 200 unless the server blows up, in which case 500.
@mjtamlyn I agree with you. However, sometimes you want to send a 401 Unauthorized or a 403 Forbidden. Under these circumstances, graphene should send a 401/403 HTTP status.