@@ -647,9 +647,21 @@ should be added to the above.
647
647
648
648
### application/graphql-response+json
649
649
650
- This section only applies when the response body is to use the
650
+ This section only applies when the response body uses the
651
651
` application/graphql-response+json ` media type.
652
652
653
+ With this media type, clients should process the response as a well-formed
654
+ _ GraphQL response_ independent of the HTTP status code, and should read the
655
+ response body (specifically {data} and {errors}) to determine the status of the
656
+ response.
657
+
658
+ Note: The purpose of setting a status code is to aid intermediary services and
659
+ tooling (which may not implement this specification) in understanding the rough
660
+ status of a response. This is useful in request logs, anomaly and intrusion
661
+ detection, metrics and observability, API gateways, and more. The status code is
662
+ not intended to aid the client, in fact it is recommended the client ignore the
663
+ status code when this media type is in use.
664
+
653
665
If the _ GraphQL response_ contains the {data} entry and it is not {null}, then
654
666
the server MUST reply with a ` 2xx ` status code.
655
667
@@ -665,24 +677,11 @@ and the {errors} entry, then the server SHOULD reply with `203` status code.
665
677
Note: The result of executing a GraphQL operation may contain partial data as
666
678
well as encountered errors. Errors that happen during execution of the GraphQL
667
679
operation typically become part of the result, as long as the server is still
668
- able to produce a well-formed _ GraphQL response_ . There's currently not an
669
- approved official HTTP status code to use for a "partial success," contenders
670
- include "206 Partial Content" (which requires the ` Range ` header), WebDAV's
671
- status code "207 Multi-Status", and using a custom code such as "294 Partial
672
- Success."
673
- [ IETF RFC2616 Section 6.1.1] ( https://datatracker.ietf.org/doc/html/rfc2616#section-6.1.1 )
674
- states "codes are fully defined in section 10" implying that though more codes
675
- are expected to be supported over time, valid codes must be present in this
676
- document. For compatibility reasons, using ` 203 ` seems to work the best with
677
- intermediate servers and clients. We hope to one day move to ` 294 ` if someone
678
- can push it through the IETF review process. Using ` 4xx ` and ` 5xx ` status codes
679
- in this situation is not appropriate - since no _ GraphQL request error_ has
680
- occurred it is seen as a "partial response" or "partial success". Note that this
681
- use of HTTP 203 does not strictly align with the intended semantics of this
682
- status code, but was a pragmatic choice to maximize compatibility whilst
683
- allowing servers to indicate partial success such that intermediaries that do
684
- not implement this specification may still track the not-fully-successful
685
- request (for example, for anomaly detection).
680
+ able to produce a well-formed _ GraphQL response_ . For details of why status code
681
+ ` 203 ` is recommended, see [ Partial success] ( #sec-Partial-success ) . Using ` 4xx `
682
+ and ` 5xx ` status codes in this situation is not appropriate - since no _ GraphQL
683
+ request error_ has occurred it is seen as a "partial response" or "partial
684
+ success".
686
685
687
686
If the _ GraphQL response_ does not contain the {data} entry then the server MUST
688
687
reply with a ` 4xx ` or ` 5xx ` status code as appropriate.
@@ -697,21 +696,6 @@ pass validation, then the server SHOULD reply with `400` status code.
697
696
If the client is not permitted to issue the GraphQL request then the server
698
697
SHOULD reply with ` 403 ` , ` 401 ` or similar appropriate status code.
699
698
700
- Note: When the response media type is ` application/graphql-response+json ` ,
701
- clients can rely on the response being a well-formed _ GraphQL response_
702
- regardless of the status code. Intermediary servers may use the status code to
703
- determine the status of the _ GraphQL response_ without needing to process the
704
- response body.
705
-
706
- A client should process a GraphQL response that uses the
707
- ` application/graphql-response+json ` media type independent of which HTTP status
708
- code it uses, instead reading the response body to determine how to handle the
709
- request.
710
-
711
- Note: For the avoidance of doubt, GraphQL clients, once they have established
712
- that the response uses ` application/graphql-response+json ` , should completely
713
- ignore the HTTP status code.
714
-
715
699
#### Examples
716
700
717
701
The following examples provide guidance on how to deal with specific error cases
@@ -801,6 +785,38 @@ is met:
801
785
- the response media type is ` application/graphql-response+json ` , or
802
786
- the status code is ` 200 ` .
803
787
788
+ ## Partial success
789
+
790
+ The result of executing a GraphQL operation may contain partial data as well as
791
+ encountered errors. Errors that happen during execution of the GraphQL operation
792
+ typically become part of the result, as long as the server is still able to
793
+ produce a well-formed _ GraphQL response_ .
794
+
795
+ Using ` 4xx ` and ` 5xx ` status codes when {data} is present and non-null is not
796
+ appropriate; since no _ GraphQL request error_ has occurred it is seen as a
797
+ "partial response" or "partial success".
798
+
799
+ There's currently not an approved official HTTP status code to use for a
800
+ "partial success," contenders include "206 Partial Content" (which requires the
801
+ ` Range ` header), WebDAV's status code "207 Multi-Status", and using a custom
802
+ code such as "294 Partial Success."
803
+
804
+ [ IETF RFC2616 Section 6.1.1] ( https://datatracker.ietf.org/doc/html/rfc2616#section-6.1.1 )
805
+ states "codes are fully defined in section 10" implying that though more codes
806
+ are expected to be supported over time, valid codes must be present in this
807
+ document. For compatibility reasons, using HTTP status ` 203 ` which has no
808
+ additional requirements seems to work the best with intermediate servers and
809
+ clients, but since it does not semantically line up we only recommend its usage
810
+ alongside the ` application/graphql-response+json ` media type which makes the
811
+ meaning explicit. We hope to one day move to ` 294 ` if someone can push it
812
+ through the IETF review process.
813
+
814
+ Note that this use of HTTP 203 does not strictly align with the intended
815
+ semantics of this status code, but was a pragmatic choice to maximize
816
+ compatibility whilst allowing servers to indicate partial success such that
817
+ intermediaries that do not implement this specification may still track the
818
+ not-fully-successful request (for example, for observability).
819
+
804
820
## Security
805
821
806
822
This specification focuses solely on the intersection of GraphQL and HTTP.
0 commit comments