16
16
17
17
package com.expediagroup.graphql.generator.execution
18
18
19
+ import com.expediagroup.graphql.generator.annotations.GraphQLName
19
20
import com.expediagroup.graphql.generator.scalars.ID
20
21
import graphql.schema.DataFetchingEnvironment
21
22
import io.mockk.every
@@ -53,6 +54,15 @@ class ConvertArgumentValueTest {
53
54
assertEquals(Foo .BAR , castResult)
54
55
}
55
56
57
+ @Test
58
+ fun `renamed enum object is parsed` () {
59
+ val kParam = assertNotNull(TestFunctions ::enumInput.findParameterByName(" input" ))
60
+ val inputValue = " baz"
61
+ val result = convertArgumentValue(" input" , kParam, mapOf (" input" to inputValue))
62
+ val castResult = assertIs<Foo >(result)
63
+ assertEquals(Foo .BAZ , castResult)
64
+ }
65
+
56
66
@Test
57
67
fun `generic map object is parsed` () {
58
68
val kParam = assertNotNull(TestFunctions ::inputObject.findParameterByName(" input" ))
@@ -210,6 +220,23 @@ class ConvertArgumentValueTest {
210
220
assertEquals(" 1234" , result.value)
211
221
}
212
222
223
+ @Test
224
+ fun `input object with renamed fields is correctly deserialized` () {
225
+ val kParam = assertNotNull(TestFunctions ::inputObjectRenamed.findParameterByName(" input" ))
226
+ val result = convertArgumentValue(
227
+ " input" ,
228
+ kParam,
229
+ mapOf (
230
+ " input" to mapOf (
231
+ " bar" to " renamed"
232
+ )
233
+ )
234
+ )
235
+
236
+ val castResult = assertIs<TestInputRenamed >(result)
237
+ assertEquals(" renamed" , castResult.foo)
238
+ }
239
+
213
240
class TestFunctions {
214
241
fun enumInput (input : Foo ): String = TODO ()
215
242
fun idInput (input : ID ): String = TODO ()
@@ -222,16 +249,20 @@ class ConvertArgumentValueTest {
222
249
fun optionalInputObject (input : OptionalInput <TestInput >): String = TODO ()
223
250
fun optionalInputListObject (input : OptionalInput <List <TestInput >>): String = TODO ()
224
251
fun stringInput (input : String ): String = TODO ()
252
+ fun inputObjectRenamed (input : TestInputRenamed ): String = TODO ()
225
253
}
226
254
227
255
class TestInput (val foo : String , val bar : String? = null , val baz : List <String >? = null , val qux : String? = null )
228
256
class TestInputNested (val foo : String? = " foo" , val bar : String? = " bar" , val nested : TestInputNestedType ? = TestInputNestedType ())
229
257
class TestInputNestedType (val value : String = " nested default value" )
230
- class TestInputNullableScalar (val foo : String , val id : ID ? = null )
258
+ class TestInputNullableScalar (val foo : String? = null , val id : ID ? = null )
231
259
class TestInputNotNullableScalar (val foo : String , val id : ID = ID ("1234"))
232
260
261
+ class TestInputRenamed (@GraphQLName(" bar" ) val foo : String )
262
+
233
263
enum class Foo {
234
264
BAR ,
265
+ @GraphQLName(" baz" )
235
266
BAZ
236
267
}
237
268
}
0 commit comments