Skip to content

Commit

Permalink
Start building against Spring GraphQL 1.1.1-SNAPSHOT
Browse files Browse the repository at this point in the history
  • Loading branch information
bclozel committed Dec 7, 2022
1 parent 50be8cb commit ce33ec1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
Expand Up @@ -85,8 +85,9 @@
@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);

Expand Down
Expand Up @@ -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
Expand All @@ -112,7 +113,7 @@ public RouterFunction<ServerResponse> graphQlRouterFunction(GraphQlHttpHandler h
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());
Expand Down
Expand Up @@ -80,8 +80,8 @@ 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/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");
});
}

Expand Down Expand Up @@ -175,7 +175,7 @@ private void testWithWebClient(Consumer<WebTestClient> consumer) {
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);
});
Expand Down
Expand Up @@ -87,7 +87,7 @@ void simpleQueryShouldWork() {
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"));
});
}
Expand Down Expand Up @@ -179,9 +179,8 @@ void shouldRegisterHints() {

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);
});
}
Expand Down
2 changes: 1 addition & 1 deletion spring-boot-project/spring-boot-dependencies/build.gradle
Expand Up @@ -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",
Expand Down
Expand Up @@ -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();
}
Expand Down

0 comments on commit ce33ec1

Please sign in to comment.