Skip to content

Commit 5df2785

Browse files
committed
fix: added missing GET method check; added integration test
1 parent 548482b commit 5df2785

File tree

2 files changed

+85
-1
lines changed
  • examples/server/spring-server/src/test/kotlin/com/expediagroup/graphql/examples/server/spring/query
  • servers/graphql-kotlin-spring-server/src/main/kotlin/com/expediagroup/graphql/server/spring/execution

2 files changed

+85
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2022 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.expediagroup.graphql.examples.server.spring.query
18+
19+
import com.expediagroup.graphql.examples.server.spring.GRAPHQL_MEDIA_TYPE
20+
import com.expediagroup.graphql.examples.server.spring.verifyData
21+
import org.junit.jupiter.api.Test
22+
import org.junit.jupiter.api.TestInstance
23+
import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS
24+
import org.springframework.beans.factory.annotation.Autowired
25+
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient
26+
import org.springframework.boot.test.context.SpringBootTest
27+
import org.springframework.http.MediaType.APPLICATION_JSON
28+
import org.springframework.test.web.reactive.server.WebTestClient
29+
30+
@SpringBootTest(
31+
properties = ["graphql.automaticPersistedQueries.enabled=true"]
32+
)
33+
@AutoConfigureWebTestClient
34+
@TestInstance(PER_CLASS)
35+
class APQQueryIT(@Autowired private val testClient: WebTestClient) {
36+
37+
@Test
38+
fun `verify GET persisted query with hash only followed by POST with hash`() {
39+
val query = "simpleDeprecatedQuery"
40+
41+
testClient.get()
42+
.uri { builder ->
43+
builder.path("/graphql")
44+
.queryParam("extensions", "{extension}")
45+
.build("""{"persistedQuery":{"version":1,"sha256Hash":"aee64e0a941589ff06b717d4930405f3eafb089e687bef6ece5719ea6a4e7f35"}}""")
46+
}
47+
.exchange()
48+
.expectBody().json(
49+
"""
50+
{
51+
errors: [
52+
{
53+
message: "PersistedQueryNotFound"
54+
}
55+
]
56+
}
57+
""".trimIndent()
58+
)
59+
60+
val expectedData = "false"
61+
62+
testClient.post()
63+
.uri { builder ->
64+
builder.path("/graphql")
65+
.queryParam("extensions", "{extension}")
66+
.build("""{"persistedQuery":{"version":1,"sha256Hash":"aee64e0a941589ff06b717d4930405f3eafb089e687bef6ece5719ea6a4e7f35"}}""")
67+
}
68+
.accept(APPLICATION_JSON)
69+
.contentType(GRAPHQL_MEDIA_TYPE)
70+
.bodyValue("query { $query }")
71+
.exchange()
72+
.verifyData(query, expectedData)
73+
74+
testClient.get()
75+
.uri { builder ->
76+
builder.path("/graphql")
77+
.queryParam("extensions", "{extension}")
78+
.build("""{"persistedQuery":{"version":1,"sha256Hash":"aee64e0a941589ff06b717d4930405f3eafb089e687bef6ece5719ea6a4e7f35"}}""")
79+
}
80+
.exchange()
81+
.verifyData(query, expectedData)
82+
}
83+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ open class SpringGraphQLRequestParser(
5353

5454
private fun ServerRequest.hasQueryParam() = queryParam(REQUEST_PARAM_QUERY).isPresent
5555

56-
private fun ServerRequest.isGetPersistedQuery() = queryParam(REQUEST_PARAM_EXTENSIONS).getOrNull()?.contains(REQUEST_PARAM_PERSISTED_QUERY) == true
56+
private fun ServerRequest.isGetPersistedQuery() =
57+
method() == HttpMethod.GET && queryParam(REQUEST_PARAM_EXTENSIONS).getOrNull()?.contains(REQUEST_PARAM_PERSISTED_QUERY) == true
5758

5859
private fun getRequestFromGet(serverRequest: ServerRequest): GraphQLServerRequest {
5960
val query = serverRequest.queryParam(REQUEST_PARAM_QUERY).orElse("")

0 commit comments

Comments
 (0)