Skip to content

Commit c5fef9b

Browse files
committed
Document GraphQL over HTTP spec support
This commit concludes the support for the "GraphQL over HTTP" spec, with both clients and servers complying with the expected behavior for the "application/graphql-response+json" response media type. Closes gh-1117
1 parent 5d615eb commit c5fef9b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

spring-graphql-docs/modules/ROOT/pages/transports.adoc

+10-4
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ equivalent functionality, but rely on blocking vs non-blocking I/O respectively
1515
writing the HTTP response.
1616

1717
Requests must use HTTP POST with `"application/json"` as content type and GraphQL request details
18-
included as JSON in the request body, as defined in the proposed
18+
included as JSON in the request body. Clients can request the `"application/graphql-response+json"` media type
19+
to get the behavior defined in the official
1920
https://github.com/graphql/graphql-over-http/blob/main/spec/GraphQLOverHTTP.md[GraphQL over HTTP] specification.
20-
Once the JSON body has been successfully decoded, the HTTP response status is always 200 (OK),
21+
If the client doesn't express any preference, this will be the content type of choice.
22+
Clients can also request the legacy `"application/json"` media type to get the traditional HTTP behavior.
23+
24+
In practice, GraphQL HTTP clients should expect 4xx/5xx HTTP responses if the server is unavailable, security credentials
25+
are missing or if the request body is not valid JSON. `"application/graphql-response+json"` responses will also use
26+
4xx statuses if the GraphQL document sent by the client cannot be parsed or is considered invalid by the GraphQL engine.
27+
In this case, `"application/json"` responses will still use 200 (OK).
28+
Once the GraphQL request has been successfully validated, the HTTP response status is always 200 (OK),
2129
and any errors from GraphQL request execution appear in the "errors" section of the GraphQL response.
22-
The default and preferred choice of media type is `"application/graphql-response+json"`, but `"application/json"`
23-
is also supported, as described in the specification.
2430

2531
`GraphQlHttpHandler` can be exposed as an HTTP endpoint by declaring a `RouterFunction`
2632
bean and using the `RouterFunctions` from Spring MVC or WebFlux to create the route. The

0 commit comments

Comments
 (0)