question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HTTP Status 200 when a mutation fails

See original GitHub issue

I’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:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

24reactions
mjtamlyncommented, May 24, 2016

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.

6reactions
helpsecommented, Jul 25, 2018

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found