Skip to content

Commit 1fbcb8f

Browse files
authored
Keep response content type to application/json as default instead of application/graphql-response+json (#1832)
### 📝 Description Most clients will request with `*/*` unless an any MediaType is specified. However, the `*/*` was not taken into account in current implementation. I change to keep `application/json` as default instead of `application/graphql-response+json`. ### 🔗 Related Issues #1831 #1573 #1699
1 parent 4052554 commit 1fbcb8f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

servers/graphql-kotlin-spring-server/src/main/kotlin/com/expediagroup/graphql/server/spring/GraphQLRoutesConfiguration.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class GraphQLRoutesConfiguration(
4949
val acceptMediaType = serverRequest
5050
.headers()
5151
.accept()
52-
.find { it.includes(MediaType.APPLICATION_GRAPHQL_RESPONSE) }
52+
.find { it != MediaType.ALL && it.includes(MediaType.APPLICATION_GRAPHQL_RESPONSE) }
5353
?.let { MediaType.APPLICATION_GRAPHQL_RESPONSE }
5454
?: MediaType.APPLICATION_JSON
5555
if (graphQLResponse != null) {

servers/graphql-kotlin-spring-server/src/test/kotlin/com/expediagroup/graphql/server/spring/routes/RouteConfigurationIT.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,18 @@ class RouteConfigurationIT(@Autowired private val testClient: WebTestClient) {
205205
.verifyGraphQLRoute("Hello POST application/graphql!")
206206
}
207207

208+
@Test
209+
fun `verify POST graphQL request without response content type`() {
210+
testClient.post()
211+
.uri("/graphql")
212+
.contentType(MediaType.APPLICATION_JSON)
213+
.bodyValue(GraphQLRequest("query { hello(name: \"POST application/graphql\") }"))
214+
.exchange()
215+
.expectHeader()
216+
.contentType(MediaType.APPLICATION_JSON)
217+
.verifyGraphQLRoute("Hello POST application/graphql!")
218+
}
219+
208220
@Test
209221
fun `verify POST request with XML content type will result in HTTP 400 bad request`() {
210222
testClient.post()

0 commit comments

Comments
 (0)