@@ -31,7 +31,7 @@ public static String map(MappingContext mappingContext, Value<?> defaultValue, T
3131 return mapObject ((ObjectValue ) defaultValue );
3232 }
3333 if (defaultValue instanceof ArrayValue ) {
34- return mapArray (mappingContext , (ArrayValue ) defaultValue , graphQLType );
34+ return mapArray (mappingContext , graphQLType , (ArrayValue ) defaultValue );
3535 }
3636 // no default value, or not a known type
3737 return null ;
@@ -74,17 +74,20 @@ private static String mapObject(ObjectValue defaultValue) {
7474 return null ;
7575 }
7676
77- private static String mapArray (MappingContext mappingContext , ArrayValue defaultValue , Type <?> graphQLType ) {
78- if (!( graphQLType instanceof ListType ) ) {
79- throw new IllegalArgumentException ( "Unexpected array default value for non-list type" );
77+ private static String mapArray (MappingContext mappingContext , Type <?> graphQLType , ArrayValue defaultValue ) {
78+ if (graphQLType instanceof NonNullType ) {
79+ return mapArray ( mappingContext , (( NonNullType ) graphQLType ). getType (), defaultValue );
8080 }
81- List <Value > values = defaultValue .getValues ();
82- if (values .isEmpty ()) {
83- return "java.util.Collections.emptyList()" ;
81+ if (graphQLType instanceof ListType ) {
82+ List <Value > values = defaultValue .getValues ();
83+ if (values .isEmpty ()) {
84+ return "java.util.Collections.emptyList()" ;
85+ }
86+ Type <?> elementType = ((ListType ) graphQLType ).getType ();
87+ return values .stream ()
88+ .map (v -> map (mappingContext , v , elementType ))
89+ .collect (Collectors .joining (", " , "java.util.Arrays.asList(" , ")" ));
8490 }
85- Type <?> elementType = ((ListType ) graphQLType ).getType ();
86- return values .stream ()
87- .map (v -> map (mappingContext , v , elementType ))
88- .collect (Collectors .joining (", " , "java.util.Arrays.asList(" , ")" ));
91+ throw new IllegalArgumentException ("Unexpected array default value for non-list type" );
8992 }
9093}
0 commit comments