Skip to content

Commit 611d794

Browse files
committed
Drop backwards compatibility
1 parent 4d1df1f commit 611d794

1 file changed

Lines changed: 25 additions & 205 deletions

File tree

spec/GraphQLOverHTTP.md

Lines changed: 25 additions & 205 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ using the JSON encoding for GraphQL requests:
183183

184184
And for a _GraphQL response_:
185185

186-
| Name | Description |
187-
| ----------------------------------- | ------------------------------------------------------------------ |
188-
| `application/graphql-response+json` | The preferred type for server responses; better HTTP compatibility |
189-
| `application/json` | An alternative type for responses (to support legacy clients) |
186+
| Name | Description |
187+
| ----------------------------------- | -------------------------------------- |
188+
| `application/graphql-response+json` | The preferred type for server responses |
189+
| `application/json` | An alternative type for responses |
190190

191191
For details of the shapes of these JSON payloads, please see
192192
[Request](#sec-Request) and [Response](#sec-Response).
@@ -257,20 +257,12 @@ client gets something useful, it needs to indicate the media types it supports.
257257
The client MUST include the media type `application/graphql-response+json` in
258258
the `Accept` header.
259259

260-
If the client knows that the server supports
261-
`application/graphql-response+json`, it is RECOMMENDED that the client set the
262-
`Accept` header to `application/graphql-response+json`. Otherwise, to maximize
263-
compatibility the client SHOULD include the media type `application/json` in the
264-
`Accept` header and it is RECOMMENDED that the client set the `Accept` header to
265-
`application/graphql-response+json, application/json;q=0.9`.
260+
It is RECOMMENDED that the client set the `Accept` header to
261+
`application/graphql-response+json`.
266262

267-
Note: The `q=0.9` parameter tells content negotiation that `application/json`
268-
should only be used if `application/graphql-response+json` is not supported.
269-
270-
The `application/graphql-response+json` media type adds improved support for
271-
HTTP status codes compared to the legacy `application/json` media type. When
272-
accepting both media types, the client SHOULD indicate it prefers
273-
`application/graphql-response+json` over `application/json`.
263+
The client MAY additionally include the media type `application/json` in the
264+
`Accept` header. When accepting both media types, the client SHOULD indicate it
265+
prefers `application/graphql-response+json` over `application/json`.
274266

275267
## GET
276268

@@ -461,33 +453,13 @@ one of the media types it has requested, hence `406 Not Acceptable` being the
461453
recommended response. However, the server authors may know better about the
462454
specific clients consuming their endpoint, thus both approaches are permitted.
463455

464-
A server MUST support responses using at least one of the official GraphQL
465-
response media types.
466-
467-
For maximal compatibility, a _server_ SHOULD support using both the
468-
`application/json` and the `application/graphql-response+json` media types for
469-
responses.
470-
471-
Each newly created or updated GraphQL _server_ SHOULD support responses using
472-
the `application/graphql-response+json` media type.
473-
474-
:: A _legacy server_ is a _server_ that does not support responses using the
456+
A _server_ MUST support responses using the
475457
`application/graphql-response+json` media type.
476458

477-
Note: Prior to this specification, the media type `application/json` was in wide
478-
use for the HTTP response payload type. Unfortunately this means clients cannot
479-
trust responses from the server that do not use an HTTP 2xx status code (since
480-
these replies may come from non-compliant HTTP servers or proxies somewhere in
481-
the request chain). For this reason, this specification introduces the
482-
`application/graphql-response+json` media type on responses; however support for
483-
this new media type is optional to allow legacy servers time to transition.
484-
485-
A server MAY choose to not support the `application/json` response media type,
486-
however doing so may limit compatibility with existing clients, so it is only
487-
recommended when creating a new GraphQL service.
459+
A server MAY additionally support the `application/json` response media type.
488460

489-
Note: Servers may wish to enforce that clients use the
490-
`application/graphql-response+json` data type so that related HTTP tooling may
461+
Note: Servers may wish to only support the
462+
`application/graphql-response+json` media type so that related HTTP tooling may
491463
utilize the HTTP status codes of responses without having to be GraphQL-aware.
492464

493465
## Validation
@@ -515,144 +487,12 @@ execution regardless of validation errors.
515487
## Status Codes
516488

517489
In case of errors that completely prevent the generation of a well-formed
518-
_GraphQL response_, the server SHOULD respond with the appropriate status code
490+
_GraphQL response_, the server MUST respond with the appropriate status code
519491
depending on the concrete error condition, and MUST NOT respond with a `2xx`
520-
status code when using the `application/graphql-response+json` media type.
492+
status code.
521493

522494
Note: Typically the appropriate status code will be `400` (Bad Request).
523495

524-
Note: This rule is "should" to maintain compatibility with legacy servers which
525-
can return 200 status codes even when this type of error occurs, but only when
526-
not using the `application/graphql-response+json` media type.
527-
528-
Otherwise, the status codes depends on the media type with which the GraphQL
529-
response will be served:
530-
531-
### application/json
532-
533-
This section only applies when the response body is to use the
534-
`application/json` media type.
535-
536-
The server SHOULD use the `200` status code for every response to a well-formed
537-
_GraphQL-over-HTTP request_, independent of any _GraphQL request error_ or
538-
_GraphQL field error_ raised.
539-
540-
If the response uses a non-`200` status code then the client MUST NOT rely on
541-
the body to be a well-formed _GraphQL response_.
542-
543-
Note: A status code in the `4xx` or `5xx` ranges or status code `203` (and maybe
544-
others) could originate from an intermediary; since the client cannot determine
545-
if an `application/json` response with arbitrary status code is a well-formed
546-
_GraphQL response_ (because it cannot trust the source) the server must use
547-
`200` status code to guarantee to the client that the response has not been
548-
generated or modified by an intermediary. See
549-
[processing a response](#sec-Processing-a-response) for more details.
550-
551-
If the _GraphQL response_ contains a non-null {data} entry then the server MUST
552-
use the `200` status code.
553-
554-
Note: This indicates that no _GraphQL request error_ was raised, though one or
555-
more _GraphQL field error_ may have been raised this is still a successful
556-
execution - see "partial response" in the GraphQL specification.
557-
558-
The server SHOULD NOT use a `4xx` or `5xx` status code for a response to a
559-
well-formed _GraphQL-over-HTTP request_.
560-
561-
Note: For compatibility with legacy servers, this specification allows the use
562-
of `4xx` or `5xx` status codes for a failed well-formed _GraphQL-over-HTTP
563-
request_ where the response uses the `application/json` media type, but it is
564-
strongly discouraged. To use `4xx` and `5xx` status codes in these situations,
565-
please use the `application/graphql-response+json` media type.
566-
567-
If the URL is not used for other purposes, the server SHOULD use a `4xx` status
568-
code to respond to a request that is not a well-formed _GraphQL-over-HTTP
569-
request_.
570-
571-
Note: For compatibility with legacy servers, this specification allows the use
572-
of `2xx` or `5xx` status codes when responding to invalid requests using the
573-
`application/json` media type, but it is strongly discouraged.
574-
575-
Note: URLs that enable GraphQL requests may enable other types of requests - see
576-
the [URL](#url) section.
577-
578-
#### Examples
579-
580-
The following examples provide guidance on how to deal with specific error cases
581-
when using the `application/json` media type to encode the response body:
582-
583-
##### JSON parsing failure
584-
585-
For example a POST request body of `NONSENSE` or `{"query":` (note: invalid
586-
JSON).
587-
588-
Requests that the server cannot interpret SHOULD result in status code `400`
589-
(Bad Request).
590-
591-
##### Invalid parameters
592-
593-
For example a POST request body of `{"qeury": "{__typename}"}` (note: typo) or
594-
`{"query": "query Q ($i:Int!) { q(i: $i) }", "variables": [7]}` (note: invalid
595-
shape for `variables`).
596-
597-
A request that does not constitute a well-formed _GraphQL-over-HTTP request_
598-
SHOULD result in status code `400` (Bad Request).
599-
600-
##### Document parsing failure
601-
602-
For example a POST request body of `{"query": "{"}`.
603-
604-
Requests where the _GraphQL document_ cannot be parsed SHOULD result in status
605-
code `200` (Okay).
606-
607-
##### Document validation failure
608-
609-
If a request fails to pass _GraphQL validation_, the server SHOULD NOT execute
610-
the request and SHOULD return a status code of `200` (Okay).
611-
612-
##### Operation cannot be determined
613-
614-
If [GetOperation()](<https://spec.graphql.org/draft/#GetOperation()>) raises a
615-
_GraphQL request error_, the server SHOULD NOT execute the request and SHOULD
616-
return a status code of `200` (Okay).
617-
618-
##### Variable coercion failure
619-
620-
If
621-
[CoerceVariableValues()](<https://spec.graphql.org/draft/#CoerceVariableValues()>)
622-
raises a _GraphQL request error_, the server SHOULD NOT execute the request and
623-
SHOULD return a status code of `200` (Okay).
624-
625-
For example the well-formed GraphQL-over-HTTP request:
626-
627-
```json
628-
{
629-
"query": "query getItemName($id: ID!) { item(id: $id) { id name } }",
630-
"variables": { "id": null }
631-
}
632-
```
633-
634-
would fail variable coercion as the value for `id` would fail to satisfy the
635-
query document's expectation that `id` is non-null.
636-
637-
##### Field errors encountered during execution
638-
639-
If the operation is executed and no _GraphQL request error_ is raised then the
640-
server SHOULD respond with a status code of `200` (Okay). This is the case even
641-
if a _GraphQL field error_ is raised during
642-
[GraphQL's ExecuteQuery()](<https://spec.graphql.org/draft/#ExecuteQuery()>) or
643-
[GraphQL's ExecuteMutation()](<https://spec.graphql.org/draft/#ExecuteMutation()>).
644-
645-
<!--
646-
When we add support for subscriptions,
647-
[GraphQL's MapSourceToResponseEvent()](<https://spec.graphql.org/draft/#MapSourceToResponseEvent()>)
648-
should be added to the above.
649-
-->
650-
651-
### application/graphql-response+json
652-
653-
This section only applies when the response body is to use the
654-
`application/graphql-response+json` media type.
655-
656496
If the _GraphQL response_ contains the {data} entry and it is not {null}, then
657497
the server MUST reply with a `2xx` status code and SHOULD reply with `200`
658498
status code.
@@ -690,27 +530,24 @@ pass validation, then the server SHOULD reply with `400` status code.
690530
If the client is not permitted to issue the GraphQL request then the server
691531
SHOULD reply with `403`, `401` or similar appropriate status code.
692532

693-
Note: When the response media type is `application/graphql-response+json`,
694-
clients can rely on the response being a well-formed _GraphQL response_
533+
Note: Clients can rely on the response being a well-formed _GraphQL response_
695534
regardless of the status code. Intermediary servers may use the status code to
696535
determine the status of the _GraphQL response_ without needing to process the
697536
response body.
698537

699-
#### Examples
538+
### Examples
700539

701-
The following examples provide guidance on how to deal with specific error cases
702-
when using the `application/graphql-response+json` media type to encode the
703-
response body:
540+
The following examples provide guidance on how to deal with specific error cases:
704541

705-
##### JSON parsing failure
542+
#### JSON parsing failure
706543

707544
For example a POST request body of `NONSENSE` or `{"query":` (note: invalid
708545
JSON).
709546

710547
Requests that the server cannot interpret should result in status code `400`
711548
(Bad Request).
712549

713-
##### Invalid parameters
550+
#### Invalid parameters
714551

715552
For example a POST request body of `{"qeury": "{__typename}"}` (note: typo) or
716553
`{"query": "query Q ($i:Int!) { q(i: $i) }", "variables": [7]}` (note: invalid
@@ -719,32 +556,32 @@ shape for `variables`).
719556
A request that does not constitute a well-formed _GraphQL-over-HTTP request_
720557
SHOULD result in status code `400` (Bad Request).
721558

722-
##### Document parsing failure
559+
#### Document parsing failure
723560

724561
For example a POST request body of `{"query": "{"}`.
725562

726563
Requests where the _GraphQL document_ cannot be parsed should result in status
727564
code `400` (Bad Request).
728565

729-
##### Document validation failure
566+
#### Document validation failure
730567

731568
If a request fails _GraphQL validation_, the server SHOULD return a status code
732569
of `400` (Bad Request) without proceeding to GraphQL execution.
733570

734-
##### Operation cannot be determined
571+
#### Operation cannot be determined
735572

736573
If [GetOperation()](<https://spec.graphql.org/draft/#GetOperation()>) raises a
737574
_GraphQL request error_, the server SHOULD NOT execute the request and SHOULD
738575
return a status code of `400` (Bad Request).
739576

740-
##### Variable coercion failure
577+
#### Variable coercion failure
741578

742579
If
743580
[CoerceVariableValues()](<https://spec.graphql.org/draft/#CoerceVariableValues()>)
744581
raises a _GraphQL request error_, the server SHOULD NOT execute the request and
745582
SHOULD return a status code of `400` (Bad Request).
746583

747-
##### Field errors encountered during execution
584+
#### Field errors encountered during execution
748585

749586
If the operation is executed and no _GraphQL request error_ is raised then the
750587
server SHOULD respond with a status code of `200` (Okay). This is the case even
@@ -768,23 +605,6 @@ response; it still indicates successful execution.
768605
This section of the specification is non-normative, even where the words and
769606
phrases specified in RFC2119 are used.
770607

771-
## Processing a response
772-
773-
In some cases, the response received by a client may not originate from a
774-
GraphQL service, but instead from an intermediary—such as an API gateway, proxy,
775-
firewall or other middleware—that does not implement this specification. Such an
776-
intermediary might produce the response to indicate an error, returning a
777-
response with `4xx` or `5xx` status code and potentially using the standard
778-
`application/json` media type to encode the reason for the error. Such a
779-
response is unlikely to be a valid GraphQL response.
780-
781-
For this reason, a client application can rely on the response being a
782-
well-formed _GraphQL response_ only if at least one of the following conditions
783-
is met:
784-
785-
- the response media type is `application/graphql-response+json`, or
786-
- the status code is `200`.
787-
788608
## Security
789609

790610
This specification focuses solely on the intersection of GraphQL and HTTP.

0 commit comments

Comments
 (0)