Support "application/graphql+json" media type in GraphQL HTTP mapping

As seen in spring-projects/spring-graphql#108, the GraphQL HTTP spec now
requires the "application/graphql+json" media type and accepts
"application/json" for backwards compatibility.

This commit updates the `RouterFunction` definition for the GraphQL HTTP
endpoints so that both types are accepted.

Closes gh-30407
This commit is contained in:
Brian Clozel
2022-04-04 16:45:11 +02:00
parent d476d8e37b
commit 1c71567c94
7 changed files with 17 additions and 16 deletions

View File

@@ -79,7 +79,7 @@ class HttpGraphQlTesterContextCustomizerIntegrationTests {
@Override
public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
response.setStatusCode(HttpStatus.OK);
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
response.getHeaders().setContentType(MediaType.APPLICATION_GRAPHQL);
return response.writeWith(Mono.just(factory.wrap("{\"data\":{}}".getBytes())));
}

View File

@@ -79,7 +79,7 @@ class HttpGraphQlTesterContextCustomizerWithCustomBasePathTests {
@Override
public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
response.setStatusCode(HttpStatus.OK);
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
response.getHeaders().setContentType(MediaType.APPLICATION_GRAPHQL);
return response.writeWith(Mono.just(factory.wrap("{\"data\":{}}".getBytes())));
}

View File

@@ -70,7 +70,7 @@ class HttpGraphQlTesterContextCustomizerWithCustomContextPathTests {
@RestController
static class TestController {
@PostMapping(path = "/graphql", produces = MediaType.APPLICATION_JSON_VALUE)
@PostMapping(path = "/graphql", produces = MediaType.APPLICATION_GRAPHQL_VALUE)
String graphql() {
return "{}";
}