Skip to content

Commit f852682

Browse files
benjieghmcadamsspawnia
authored
Add "Note" after various "SHOULD" rules in the spec (#197)
Co-authored-by: Gabriel McAdams <[email protected]> Co-authored-by: Benedikt Franke <[email protected]>
1 parent cabdc15 commit f852682

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

spec/GraphQLOverHTTP.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ The GraphQL specification allows for many
169169
Servers and clients MUST support JSON and MAY support other, additional
170170
serialization formats.
171171

172+
Note: Allowing other media types, particularly on requests, can be insecure.
173+
172174
For consistency and ease of notation, examples of the response are given in JSON
173175
throughout this specification.
174176

@@ -240,9 +242,17 @@ A client SHOULD indicate the media types that it supports in responses using the
240242
`Accept` HTTP header as specified in
241243
[RFC7231](https://datatracker.ietf.org/doc/html/rfc7231).
242244

245+
Note: If a client does not supply the `Accept` header then the server may
246+
respond with an error, or with any content type it chooses. To ensure your
247+
client gets something useful, it should indicate the media types it supports.
248+
243249
If the client supplies an `Accept` header, the client SHOULD include the media
244250
type `application/graphql+json` in the `Accept` header.
245251

252+
Note: From 1st Jan 2025, every _server_ and _client_ must support
253+
`application/graphql+json`, so including this in the Accept header should give
254+
your client compatibility with any _server_.
255+
246256
### Legacy Watershed
247257

248258
Before `2025-01-01T00:00:00Z`, if the client supplies an `Accept` header, the
@@ -323,12 +333,20 @@ type (as indicated by the `Content-Type` header).
323333
If the client does not supply a `Content-Type` header with a POST request, the
324334
server SHOULD reject the request using the appropriate `4xx` status code.
325335

336+
Note: Rejecting such requests encourages clients to supply a `Content-Type`
337+
header with every POST request. A server has the option to assume any media type
338+
they wish when none is supplied, with the understanding that parsing the request
339+
may fail.
340+
326341
A server MAY support POST requests encoded with and/or accepting other media
327342
types.
328343

329344
If a client does not know the media types the server supports then it SHOULD
330345
encode the request body in JSON (i.e. with `Content-Type: application/json`).
331346

347+
Note: Request encoding with media type `application/json` is supported by every
348+
compliant _server_.
349+
332350
### JSON Encoding
333351

334352
When encoded in JSON, a GraphQL-over-HTTP request is a JSON object (map), with
@@ -465,6 +483,9 @@ depending on the concrete error condition.
465483

466484
Note: Typically this will be the `400` (Bad Request) status code.
467485

486+
Note: This rule is "should" to maintain compatibility with legacy servers which
487+
can return 200 status codes even when this type of error occurs.
488+
468489
Otherwise, the status codes depends on the media type with which the GraphQL
469490
response will be served:
470491

0 commit comments

Comments
 (0)