@@ -306,7 +306,6 @@ class SchemaParser internal constructor(
306306 val graphQLDirective = GraphQLDirective .newDirective()
307307 .name(directive.name)
308308 .apply {
309- // TODO or enforce directive to be declared instead of inferring the type
310309 directive.arguments.forEach { arg ->
311310 argument(GraphQLArgument .newArgument()
312311 .name(arg.name)
@@ -331,13 +330,38 @@ class SchemaParser internal constructor(
331330 is StringValue -> return Scalars .GraphQLString
332331 is IntValue -> return Scalars .GraphQLInt
333332 is BooleanValue -> return Scalars .GraphQLBoolean
334- is ArrayValue -> {
335- TODO ()
336- }
333+ is ArrayValue -> return GraphQLList .list(buildDirectiveInputType(getArrayValueWrappedType(value)))
337334 else -> throw SchemaError (" Directive values of type '${value::class .simpleName} ' are not supported yet." )
338335 }
339336 }
340337
338+ private fun getArrayValueWrappedType (value : ArrayValue ): Value <* > {
339+ // empty array [] is equivalent to [null]
340+ if (value.values.isEmpty()) {
341+ return NullValue .newNullValue().build()
342+ }
343+
344+ // get rid of null values
345+ val nonNullValueList = value.values.filter { v -> v !is NullValue }
346+
347+ // [null, null, ...] unwrapped is null
348+ if (nonNullValueList.isEmpty()) {
349+ return NullValue .newNullValue().build()
350+ }
351+
352+ // make sure the array isn't polymorphic
353+ val distinctTypes = nonNullValueList
354+ .map { it::class .java }
355+ .distinct()
356+
357+ if (distinctTypes.size > 1 ) {
358+ throw SchemaError (" Arrays containing multiple types of values are not supported yet." )
359+ }
360+
361+ // peek at first value, value exists and is assured to be non-null
362+ return nonNullValueList[0 ]
363+ }
364+
341365 private fun buildDefaultValue (value : Value <* >? ): Any? {
342366 return when (value) {
343367 null -> null
0 commit comments