Start building against Spring GraphQL 1.1.1-SNAPSHOT

See gh-33477
This commit is contained in:
Brian Clozel 2022-12-07 14:42:01 +01:00
parent 50be8cbf91
commit ce33ec19cd
6 changed files with 18 additions and 16 deletions

View File

@ -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);

View File

@ -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());

View File

@ -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);
});

View File

@ -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);
});
}

View File

@ -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",

View File

@ -47,13 +47,14 @@ public class GraphQlTesterAutoConfiguration {
@Bean
@ConditionalOnBean(ExecutionGraphQlService.class)
@ConditionalOnMissingBean
@SuppressWarnings("removal")
public ExecutionGraphQlServiceTester graphQlTester(ExecutionGraphQlService graphQlService,
ObjectProvider<ObjectMapper> 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();
}