Skip to content

Commit

Permalink
Do not use application/graphql as default MIME type
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bclozel committed May 4, 2022
1 parent 31cabba commit 5352c44
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
Expand Up @@ -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));
}

}
Expand Up @@ -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");
});
}
Expand Down Expand Up @@ -151,8 +151,8 @@ private void testWithWebClient(Consumer<WebTestClient> 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);
});
Expand Down
Expand Up @@ -79,7 +79,7 @@ static class TestHandler implements HttpHandler {
@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())));
}

Expand Down
Expand Up @@ -79,7 +79,7 @@ static class TestHandler implements HttpHandler {
@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())));
}

Expand Down
Expand Up @@ -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 "{}";
}
Expand Down

0 comments on commit 5352c44

Please sign in to comment.