You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: implemented persisted queries for GET methods with only SHA-256 hash of query string (#2067)
### 📝 Description
According to the GraphQL APQ flow description, GET requests containing
only SHA-256 hash of the query should be checked in cache and respond
with PERSISTED_QUERY_NOT_FOUND error if request is not cached.
Both Ktor and Spring server implementations didn't handle this first
query without a query param.
I tried to implement the change without breaking existing behaviours, as
a query param is expected to take precedence over post body, for
example, as in one of the tests in RouteConfigurationIT.
### 🔗 Related Issues
#2065
Copy file name to clipboardExpand all lines: servers/graphql-kotlin-ktor-server/src/main/kotlin/com/expediagroup/graphql/server/ktor/KtorGraphQLRequestParser.kt
val query = request.queryParameters[REQUEST_PARAM_QUERY] ?:throwIllegalStateException("Invalid HTTP request - GET request has to specify query parameter")
Copy file name to clipboardExpand all lines: servers/graphql-kotlin-ktor-server/src/test/kotlin/com/expediagroup/graphql/server/ktor/GraphQLPluginTest.kt
+10
Original file line number
Diff line number
Diff line change
@@ -134,6 +134,16 @@ class GraphQLPluginTest {
134
134
}
135
135
}
136
136
137
+
@Test
138
+
fun`server should return Method Not Allowed for Mutation GET requests with persisted query`() {
Copy file name to clipboardExpand all lines: servers/graphql-kotlin-ktor-server/src/test/kotlin/com/expediagroup/graphql/server/ktor/KtorGraphQLRequestParserTest.kt
+24
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,7 @@ class KtorGraphQLRequestParserTest {
35
35
fun`parseRequest should throw IllegalStateException if request method is GET without query`() = runTest {
36
36
val request = mockk<ApplicationRequest>(relaxed =true) {
37
37
every { queryParameters[REQUEST_PARAM_QUERY] } returns null
38
+
every { queryParameters[REQUEST_PARAM_EXTENSIONS] } returns null
38
39
every { local.method } returns HttpMethod.Get
39
40
}
40
41
assertFailsWith<IllegalStateException> {
@@ -60,6 +61,7 @@ class KtorGraphQLRequestParserTest {
60
61
every { queryParameters[REQUEST_PARAM_QUERY] } returns "{ foo }"
61
62
every { queryParameters[REQUEST_PARAM_OPERATION_NAME] } returns null
62
63
every { queryParameters[REQUEST_PARAM_VARIABLES] } returns null
64
+
every { queryParameters[REQUEST_PARAM_EXTENSIONS] } returns null
63
65
every { local.method } returns HttpMethod.Get
64
66
}
65
67
val graphQLRequest = parser.parseRequest(serverRequest)
@@ -76,6 +78,7 @@ class KtorGraphQLRequestParserTest {
76
78
every { queryParameters[REQUEST_PARAM_QUERY] } returns "query MyFoo { foo }"
77
79
every { queryParameters[REQUEST_PARAM_OPERATION_NAME] } returns "MyFoo"
78
80
every { queryParameters[REQUEST_PARAM_VARIABLES] } returns """{"a":1}"""
81
+
every { queryParameters[REQUEST_PARAM_EXTENSIONS] } returns null
79
82
every { local.method } returns HttpMethod.Get
80
83
}
81
84
val graphQLRequest = parser.parseRequest(serverRequest)
@@ -86,6 +89,27 @@ class KtorGraphQLRequestParserTest {
Copy file name to clipboardExpand all lines: servers/graphql-kotlin-spring-server/src/main/kotlin/com/expediagroup/graphql/server/spring/execution/SpringGraphQLRequestParser.kt
Copy file name to clipboardExpand all lines: servers/graphql-kotlin-spring-server/src/test/kotlin/com/expediagroup/graphql/server/spring/execution/SpringGraphQLRequestParserTest.kt
0 commit comments