From 5352c441e1a5ea7603ec65623ba57a36e5c7612a Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Wed, 4 May 2022 13:04:14 +0200 Subject: [PATCH] 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 --- .../rsocket/RSocketGraphQlClientAutoConfiguration.java | 2 +- .../reactive/GraphQlWebFluxAutoConfigurationTests.java | 6 +++--- .../HttpGraphQlTesterContextCustomizerIntegrationTests.java | 2 +- ...aphQlTesterContextCustomizerWithCustomBasePathTests.java | 2 +- ...QlTesterContextCustomizerWithCustomContextPathTests.java | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/rsocket/RSocketGraphQlClientAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/rsocket/RSocketGraphQlClientAutoConfiguration.java index 63585b5559a6..1876e0958c26 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/rsocket/RSocketGraphQlClientAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/rsocket/RSocketGraphQlClientAutoConfiguration.java @@ -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)); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/reactive/GraphQlWebFluxAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/reactive/GraphQlWebFluxAutoConfigurationTests.java index 38e1d0307bb6..797ec5f2abf7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/reactive/GraphQlWebFluxAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/reactive/GraphQlWebFluxAutoConfigurationTests.java @@ -75,7 +75,7 @@ void simpleQueryShouldWork() { 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 @@ private void testWithWebClient(Consumer consumer) { 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); }); diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/graphql/tester/HttpGraphQlTesterContextCustomizerIntegrationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/graphql/tester/HttpGraphQlTesterContextCustomizerIntegrationTests.java index d319c8ff2700..b66eec19be32 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/graphql/tester/HttpGraphQlTesterContextCustomizerIntegrationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/graphql/tester/HttpGraphQlTesterContextCustomizerIntegrationTests.java @@ -79,7 +79,7 @@ static class TestHandler implements HttpHandler { @Override public Mono 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()))); } diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/graphql/tester/HttpGraphQlTesterContextCustomizerWithCustomBasePathTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/graphql/tester/HttpGraphQlTesterContextCustomizerWithCustomBasePathTests.java index 27b3fce49c14..f7167d07e104 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/graphql/tester/HttpGraphQlTesterContextCustomizerWithCustomBasePathTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/graphql/tester/HttpGraphQlTesterContextCustomizerWithCustomBasePathTests.java @@ -79,7 +79,7 @@ static class TestHandler implements HttpHandler { @Override public Mono 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()))); } diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/graphql/tester/HttpGraphQlTesterContextCustomizerWithCustomContextPathTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/graphql/tester/HttpGraphQlTesterContextCustomizerWithCustomContextPathTests.java index 786481023e98..fec60ac44248 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/graphql/tester/HttpGraphQlTesterContextCustomizerWithCustomContextPathTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/graphql/tester/HttpGraphQlTesterContextCustomizerWithCustomContextPathTests.java @@ -70,7 +70,7 @@ DispatcherServlet dispatcherServlet() { @RestController static class TestController { - @PostMapping(path = "/graphql", produces = MediaType.APPLICATION_GRAPHQL_VALUE) + @PostMapping(path = "/graphql", produces = MediaType.APPLICATION_JSON_VALUE) String graphql() { return "{}"; }