@@ -32,6 +32,32 @@ class SchemaGeneratorTest {
3232 assertEquals(1 , geo?.get(" query" )?.get(" id" ))
3333 }
3434
35+ @Test
36+ fun `Schema generator exposes arrays of primitive types as function arguments` () {
37+ val schema = toSchema(listOf (TopLevelObjectDef (QueryWithArray ())), config = testSchemaConfig)
38+ val firstArgumentType = schema.queryType.getFieldDefinition(" sumOf" ).arguments[0 ].type.deepName
39+ assertEquals(" [Int!]!" , firstArgumentType)
40+
41+ val graphQL = GraphQL .newGraphQL(schema).build()
42+ val result = graphQL.execute(" { sumOf(ints: [1, 2, 3]) }" )
43+ val sum = result.getData<Map <String , Int >>().values.first()
44+
45+ assertEquals(6 , sum)
46+ }
47+
48+ @Test
49+ fun `Schema generator exposes arrays of complex types as function arguments` () {
50+ val schema = toSchema(listOf (TopLevelObjectDef (QueryWithArray ())), config = testSchemaConfig)
51+ val firstArgumentType = schema.queryType.getFieldDefinition(" sumOfComplexArray" ).arguments[0 ].type.deepName
52+ assertEquals(" [ComplexWrappingTypeInput!]!" , firstArgumentType)
53+
54+ val graphQL = GraphQL .newGraphQL(schema).build()
55+ val result = graphQL.execute(" {sumOfComplexArray(objects: [{value: 1}, {value: 2}, {value: 3}])}" )
56+ val sum = result.getData<Map <String , Int >>().values.first()
57+
58+ assertEquals(6 , sum)
59+ }
60+
3561 @Test
3662 fun `SchemaGenerator ignores fields and functions with @Ignore` () {
3763 val schema = toSchema(listOf (TopLevelObjectDef (QueryWithIgnored ())), config = testSchemaConfig)
@@ -179,6 +205,11 @@ class SchemaGeneratorTest {
179205 fun query (@GraphQLDescription(" A GraphQL value" ) value : Int ): Geography = Geography (value, GeoType .CITY , listOf ())
180206 }
181207
208+ class QueryWithArray {
209+ fun sumOf (ints : Array <Int >): Int = ints.sum()
210+ fun sumOfComplexArray (objects : Array <ComplexWrappingType >): Int = objects.map { it.value }.sum()
211+ }
212+
182213 class QueryWithIgnored {
183214 fun query (): ResultWithIgnored ? = null
184215
@@ -200,6 +231,8 @@ class SchemaGeneratorTest {
200231 fun mutation (value : Int ): Boolean = value > 0
201232 }
202233
234+ data class ComplexWrappingType (val value : Int )
235+
203236 @GraphQLDescription(" A place" )
204237 data class Geography (
205238 val id : Int? ,
0 commit comments