@@ -519,8 +519,6 @@ _GraphQL response_, the server SHOULD respond with the appropriate status code
519
519
depending on the concrete error condition, and MUST NOT respond with a ` 2xx `
520
520
status code when using the ` application/graphql-response+json ` media type.
521
521
522
- Note: Typically the appropriate status code will be ` 400 ` (Bad Request).
523
-
524
522
Note: This rule is "should" to maintain compatibility with legacy servers which
525
523
can return 200 status codes even when this type of error occurs, but only when
526
524
not using the ` application/graphql-response+json ` media type.
@@ -678,18 +676,48 @@ since no _GraphQL request error_ has occurred it is seen as a "partial
678
676
response".
679
677
680
678
If the _ GraphQL response_ does not contain the {data} entry then the server MUST
681
- reply with a ` 4xx ` or ` 5xx ` status code as appropriate.
679
+ reply with a ` 4xx ` or ` 5xx ` status code as appropriate:
680
+
681
+ - If the failure is due to an issue in the request itself, the appropriate ` 4xx `
682
+ status code should be used:
683
+ - If an unsupported HTTP method is used, status code ` 405 ` is RECOMMENDED.
684
+ - If the ` Content-Type ` of the request is not supported, status code ` 415 ` is
685
+ RECOMMENDED.
686
+ - If none of the media types in the ` Accept ` header are supported, status code
687
+ ` 406 ` is RECOMMENDED.
688
+ - If the client did not produce a request within the time that the server was
689
+ prepared to wait, status code ` 408 ` is RECOMMENDED.
690
+ - If the size of the URI was too large, status code ` 414 ` is RECOMMENDED (and
691
+ the client should consider using ` POST ` instead).
692
+ - If the size of the request headers (or any one header) was too large, status
693
+ code ` 431 ` is RECOMMENDED.
694
+ - If the size of the ` POST ` request body was too large, status code ` 413 ` is
695
+ RECOMMENDED.
696
+ - If the JSON body of the request could not be parsed, status code ` 400 ` is
697
+ RECOMMENDED.
698
+ - If the request is not a well-formed _ GraphQL-over-HTTP request_ , status code
699
+ ` 422 ` is RECOMMENDED.
700
+ - If the GraphQL document in the request cannot be parsed, status code ` 400 `
701
+ is RECOMMENDED.
702
+ - If the request does not pass GraphQL validation, status code ` 422 ` is
703
+ RECOMMENDED.
704
+ - If the operation to execute cannot be unambiguously determined, status code
705
+ ` 422 ` is RECOMMENDED.
706
+ - If the values of the variables could not be coerced to match the operation's
707
+ variable definitions, status code ` 422 ` is RECOMMENDED.
708
+ - If the client is not permitted to issue the GraphQL request then the server
709
+ SHOULD reply with ` 401 ` , ` 403 ` or similar appropriate status code.
710
+ - If the server is a short and stout ceramic vessel, status code ` 418 ` is
711
+ RECOMMENDED.
712
+ - When the server is the reason for failure, the appropriate ` 5xx ` status code
713
+ should be used; for example, if the server is not able to execute requests at
714
+ this time due to maintenance or load-shedding then status code ` 503 ` is
715
+ RECOMMENDED.
682
716
683
717
Note: The GraphQL specification indicates that the only situation in which the
684
718
_ GraphQL response_ does not include the {data} entry is one in which the
685
719
{errors} entry is populated.
686
720
687
- If the request is not a well-formed _ GraphQL-over-HTTP request_ , or it does not
688
- pass validation, then the server SHOULD reply with ` 400 ` status code.
689
-
690
- If the client is not permitted to issue the GraphQL request then the server
691
- SHOULD reply with ` 403 ` , ` 401 ` or similar appropriate status code.
692
-
693
721
Note: When the response media type is ` application/graphql-response+json ` ,
694
722
clients can rely on the response being a well-formed _ GraphQL response_
695
723
regardless of the status code. Intermediary servers may use the status code to
@@ -717,7 +745,7 @@ For example a POST request body of `{"qeury": "{__typename}"}` (note: typo) or
717
745
shape for ` variables ` ).
718
746
719
747
A request that does not constitute a well-formed _ GraphQL-over-HTTP request_
720
- SHOULD result in status code ` 400 ` (Bad Request ).
748
+ SHOULD result in status code ` 422 ` (Unprocessable Content ).
721
749
722
750
##### Document parsing failure
723
751
@@ -729,20 +757,20 @@ code `400` (Bad Request).
729
757
##### Document validation failure
730
758
731
759
If a request fails _ GraphQL validation_ , the server SHOULD return a status code
732
- of ` 400 ` (Bad Request ) without proceeding to GraphQL execution.
760
+ of ` 422 ` (Unprocessable Content ) without proceeding to GraphQL execution.
733
761
734
762
##### Operation cannot be determined
735
763
736
764
If [ GetOperation()] ( < https://spec.graphql.org/draft/#GetOperation() > ) raises a
737
765
_ GraphQL request error_ , the server SHOULD NOT execute the request and SHOULD
738
- return a status code of ` 400 ` (Bad Request ).
766
+ return a status code of ` 422 ` (Unprocessable Content ).
739
767
740
768
##### Variable coercion failure
741
769
742
770
If
743
771
[ CoerceVariableValues()] ( < https://spec.graphql.org/draft/#CoerceVariableValues() > )
744
772
raises a _ GraphQL request error_ , the server SHOULD NOT execute the request and
745
- SHOULD return a status code of ` 400 ` (Bad Request ).
773
+ SHOULD return a status code of ` 422 ` (Unprocessable Content ).
746
774
747
775
##### Field errors encountered during execution
748
776
0 commit comments