Skip to content

Commit 550f31d

Browse files
committed
fix(spring-boot): allow nested variables (and add tests)
1 parent bce1ad4 commit 550f31d

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

graphql-kotlin-toolkit-spring-boot/src/main/kotlin/com/auritylab/graphql/kotlin/toolkit/spring/controller/AbstractController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ abstract class AbstractController(
2929
protected data class Operation(
3030
val query: String = "",
3131
val operationName: String?,
32-
val variables: Map<String, String>?
32+
val variables: Map<String, Any>?
3333
)
3434

3535
/**

graphql-kotlin-toolkit-spring-boot/src/main/kotlin/com/auritylab/graphql/kotlin/toolkit/spring/controller/GetController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ class GetController(
3737
Operation(
3838
query,
3939
operationName,
40-
variables?.let { parse<Map<String, String>>(it) }), request
40+
variables?.let { parse<Map<String, Any>>(it) }), request
4141
)
4242
}

graphql-kotlin-toolkit-spring-boot/src/test/kotlin/com/auritylab/graphql/kotlin/toolkit/spring/GraphQLControllerMockedInvocationTest.kt

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,49 @@ class GraphQLControllerMockedInvocationTest {
165165
}, any())
166166
}
167167

168+
@Test
169+
fun `(post) should handle nested variables correctly`() {
170+
val inputQuery = query()
171+
val inputOperation = UUID.randomUUID().toString()
172+
val inputVariables = mapOf(
173+
Pair("name", "test"),
174+
Pair("surname", "test"),
175+
Pair("meta", mapOf(Pair("surname", "true"), Pair("name", "false")))
176+
)
177+
val inputContent = body(inputQuery, inputOperation, inputVariables)
178+
179+
mvc.post("/graphql") {
180+
content = inputContent
181+
contentType = MediaType.APPLICATION_JSON
182+
}.andExpect { status { isOk } }
183+
184+
verify(invocation, times(1))
185+
.invoke(argThat {
186+
query == inputQuery &&
187+
operationName == inputOperation &&
188+
variables == inputVariables
189+
}, any())
190+
}
191+
192+
@Test
193+
fun `(get) should handle nested variables correctly`() {
194+
val inputQuery = query()
195+
val inputVariables = mapOf(
196+
Pair("name", "test"),
197+
Pair("surname", "test"),
198+
Pair("meta", mapOf(Pair("surname", "true"), Pair("name", "false")))
199+
)
200+
201+
mvc.get("/graphql") {
202+
param("query", inputQuery)
203+
param("variables", objectMapper.writeValueAsString(inputVariables))
204+
}.andExpect { status { isOk } }
205+
206+
// Invocation shall be called exactly once with the input variables.
207+
verify(invocation, times(1))
208+
.invoke(argThat { variables == inputVariables }, any())
209+
}
210+
168211
/**
169212
* Will create a GraphQL Query for testing purpose.
170213
*/
@@ -182,7 +225,7 @@ class GraphQLControllerMockedInvocationTest {
182225
/**
183226
* Will create a JSON encoded GraphQL body. The [query] must be given, [operationName] and [variables] are optional.
184227
*/
185-
private fun body(query: String, operationName: String?, variables: Map<String, String?>?): String {
228+
private fun body(query: String, operationName: String?, variables: Map<String, Any?>?): String {
186229
val map = mutableMapOf<String, Any>()
187230

188231
map["query"] = query

0 commit comments

Comments
 (0)