diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/reactive/GraphQlWebFluxAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/reactive/GraphQlWebFluxAutoConfiguration.java index b32ef4eb7c..9f5323d87b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/reactive/GraphQlWebFluxAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/reactive/GraphQlWebFluxAutoConfiguration.java @@ -85,8 +85,9 @@ import static org.springframework.web.reactive.function.server.RequestPredicates @ImportRuntimeHints(GraphQlWebFluxAutoConfiguration.GraphiQlResourceHints.class) public class GraphQlWebFluxAutoConfiguration { - private static final RequestPredicate SUPPORTS_MEDIATYPES = accept(MediaType.APPLICATION_GRAPHQL, - MediaType.APPLICATION_JSON).and(contentType(MediaType.APPLICATION_GRAPHQL, MediaType.APPLICATION_JSON)); + @SuppressWarnings("removal") + private static final RequestPredicate SUPPORTS_MEDIATYPES = accept(MediaType.APPLICATION_GRAPHQL_RESPONSE, + MediaType.APPLICATION_JSON, MediaType.APPLICATION_GRAPHQL).and(contentType(MediaType.APPLICATION_JSON)); private static final Log logger = LogFactory.getLog(GraphQlWebFluxAutoConfiguration.class); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfiguration.java index 33470d92f8..7fa717ca9b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfiguration.java @@ -88,8 +88,9 @@ public class GraphQlWebMvcAutoConfiguration { private static final Log logger = LogFactory.getLog(GraphQlWebMvcAutoConfiguration.class); - private static MediaType[] SUPPORTED_MEDIA_TYPES = new MediaType[] { MediaType.APPLICATION_GRAPHQL, - MediaType.APPLICATION_JSON }; + @SuppressWarnings("removal") + private static MediaType[] SUPPORTED_MEDIA_TYPES = new MediaType[] { MediaType.APPLICATION_GRAPHQL_RESPONSE, + MediaType.APPLICATION_JSON, MediaType.APPLICATION_GRAPHQL }; @Bean @ConditionalOnMissingBean @@ -112,7 +113,7 @@ public class GraphQlWebMvcAutoConfiguration { logger.info(LogMessage.format("GraphQL endpoint HTTP POST %s", path)); RouterFunctions.Builder builder = RouterFunctions.route(); builder = builder.GET(path, this::onlyAllowPost); - builder = builder.POST(path, RequestPredicates.contentType(SUPPORTED_MEDIA_TYPES) + builder = builder.POST(path, RequestPredicates.contentType(MediaType.APPLICATION_JSON) .and(RequestPredicates.accept(SUPPORTED_MEDIA_TYPES)), httpHandler::handleRequest); if (properties.getGraphiql().isEnabled()) { GraphiQlHandler graphiQLHandler = new GraphiQlHandler(path, properties.getWebsocket().getPath()); 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 ffdeac1aba..47e325bc85 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 @@ -80,8 +80,8 @@ 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/json").expectBody().jsonPath("data.bookById.name") - .isEqualTo("GraphQL for beginners"); + .expectHeader().contentType(MediaType.APPLICATION_GRAPHQL_RESPONSE_VALUE).expectBody() + .jsonPath("data.bookById.name").isEqualTo("GraphQL for beginners"); }); } @@ -175,7 +175,7 @@ class GraphQlWebFluxAutoConfigurationTests { WebTestClient client = WebTestClient.bindToApplicationContext(context).configureClient() .defaultHeaders((headers) -> { headers.setContentType(MediaType.APPLICATION_JSON); - headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_GRAPHQL_RESPONSE)); }).baseUrl(BASE_URL).build(); consumer.accept(client); }); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfigurationTests.java index a3e83069bd..9eb187b0eb 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfigurationTests.java @@ -87,7 +87,7 @@ class GraphQlWebMvcAutoConfigurationTests { String query = "{ bookById(id: \\\"book-1\\\"){ id name pageCount author } }"; MvcResult result = mockMvc.perform(post("/graphql").content("{\"query\": \"" + query + "\"}")).andReturn(); mockMvc.perform(asyncDispatch(result)).andExpect(status().isOk()) - .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_GRAPHQL)) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_GRAPHQL_RESPONSE)) .andExpect(jsonPath("data.bookById.name").value("GraphQL for beginners")); }); } @@ -179,9 +179,8 @@ class GraphQlWebMvcAutoConfigurationTests { private void testWith(MockMvcConsumer mockMvcConsumer) { this.contextRunner.run((context) -> { - MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context).defaultRequest( - post("/graphql").contentType(MediaType.APPLICATION_GRAPHQL).accept(MediaType.APPLICATION_GRAPHQL)) - .build(); + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context).defaultRequest(post("/graphql") + .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_GRAPHQL_RESPONSE)).build(); mockMvcConsumer.accept(mockMvc); }); } diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index efd8713f50..bff51fb577 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -1364,7 +1364,7 @@ bom { ] } } - library("Spring GraphQL", "1.1.0") { + library("Spring GraphQL", "1.1.1-SNAPSHOT") { group("org.springframework.graphql") { modules = [ "spring-graphql", diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/GraphQlTesterAutoConfiguration.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/GraphQlTesterAutoConfiguration.java index 1ed2087bcb..3e55dd4f0a 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/GraphQlTesterAutoConfiguration.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/GraphQlTesterAutoConfiguration.java @@ -47,13 +47,14 @@ public class GraphQlTesterAutoConfiguration { @Bean @ConditionalOnBean(ExecutionGraphQlService.class) @ConditionalOnMissingBean + @SuppressWarnings("removal") public ExecutionGraphQlServiceTester graphQlTester(ExecutionGraphQlService graphQlService, ObjectProvider objectMapperProvider) { ExecutionGraphQlServiceTester.Builder builder = ExecutionGraphQlServiceTester.builder(graphQlService); objectMapperProvider.ifAvailable((objectMapper) -> { - MediaType[] mediaTypes = new MediaType[] { MediaType.APPLICATION_JSON, MediaType.APPLICATION_GRAPHQL }; - builder.encoder(new Jackson2JsonEncoder(objectMapper, mediaTypes)); - builder.decoder(new Jackson2JsonDecoder(objectMapper, mediaTypes)); + builder.encoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_GRAPHQL_RESPONSE, + MediaType.APPLICATION_JSON, MediaType.APPLICATION_GRAPHQL)); + builder.decoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON)); }); return builder.build(); }