Do not use application/graphql as default MIME type

As seen in spring-projects/spring-graphql#375, Spring Boot should also
use "application/json" as the default MIME type but remain compatible
with "application/graphql+json" still if clients POST content with this
type or explicitly accept it.

Closes gh-30860
This commit is contained in:
Brian Clozel 2022-05-04 13:04:14 +02:00
parent 31cabba828
commit 5352c441e1
5 changed files with 7 additions and 7 deletions

View File

@ -51,7 +51,7 @@ public class RSocketGraphQlClientAutoConfiguration {
@ConditionalOnMissingBean
public RSocketGraphQlClient.Builder<?> rsocketGraphQlClientBuilder(
RSocketRequester.Builder rsocketRequesterBuilder) {
return RSocketGraphQlClient.builder(rsocketRequesterBuilder.dataMimeType(MimeTypeUtils.APPLICATION_GRAPHQL));
return RSocketGraphQlClient.builder(rsocketRequesterBuilder.dataMimeType(MimeTypeUtils.APPLICATION_JSON));
}
}

View File

@ -75,7 +75,7 @@ class GraphQlWebFluxAutoConfigurationTests {
testWithWebClient((client) -> {
String query = "{ bookById(id: \\\"book-1\\\"){ id name pageCount author } }";
client.post().uri("/graphql").bodyValue("{ \"query\": \"" + query + "\"}").exchange().expectStatus().isOk()
.expectHeader().contentType("application/graphql+json").expectBody().jsonPath("data.bookById.name")
.expectHeader().contentType("application/json").expectBody().jsonPath("data.bookById.name")
.isEqualTo("GraphQL for beginners");
});
}
@ -151,8 +151,8 @@ class GraphQlWebFluxAutoConfigurationTests {
this.contextRunner.run((context) -> {
WebTestClient client = WebTestClient.bindToApplicationContext(context).configureClient()
.defaultHeaders((headers) -> {
headers.setContentType(MediaType.APPLICATION_GRAPHQL);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_GRAPHQL));
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
}).baseUrl(BASE_URL).build();
consumer.accept(client);
});

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_GRAPHQL);
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
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_GRAPHQL);
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
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_GRAPHQL_VALUE)
@PostMapping(path = "/graphql", produces = MediaType.APPLICATION_JSON_VALUE)
String graphql() {
return "{}";
}