@@ -120,7 +120,7 @@ private Map<String, Object> coerceVariableValuesImpl(GraphQLSchema schema,
120120 boolean hasValue = rawVariables .containsKey (variableName );
121121 Object value = rawVariables .get (variableName );
122122 if (!hasValue && defaultValue != null ) {
123- Object coercedDefaultValue = coerceValueAst (fieldVisibility , variableType , defaultValue , Collections .emptyMap (), null , valueMode );
123+ Object coercedDefaultValue = coerceAstValue (fieldVisibility , variableType , defaultValue , Collections .emptyMap (), null , valueMode , false );
124124 coercedValues .put (variableName , newValue (coercedDefaultValue , variableType , valueMode ));
125125 } else if (isNonNull (variableType ) && (!hasValue || value == null )) {
126126 throw new NonNullableValueCoercedAsNullException (variableDefinition , variableType );
@@ -180,7 +180,7 @@ private Map<String, Object> getArgumentValuesImpl(GraphQLCodeRegistry codeRegist
180180 } else if (argumentValue instanceof VariableReference ) {
181181 coercedValues .put (argumentName , value );
182182 } else {
183- value = coerceValueAst (codeRegistry .getFieldVisibility (), argumentType , argument .getValue (), coercedVariables , normalizedVariables , valueMode );
183+ value = coerceAstValue (codeRegistry .getFieldVisibility (), argumentType , argument .getValue (), coercedVariables , normalizedVariables , valueMode , false );
184184 coercedValues .put (argumentName , newValue (value , argumentType , valueMode ));
185185 }
186186 } else {
@@ -364,14 +364,24 @@ private List coerceValueForList(GraphqlFieldVisibility fieldVisibility,
364364 }
365365 }
366366
367- private Object coerceValueAst (GraphqlFieldVisibility fieldVisibility ,
368- GraphQLType type ,
369- Value inputValue ,
370- Map <String , Object > coercedVariables ,
371- @ Nullable Map <String , NormalizedInputValue > normalizedVariables ,
372- ValueMode valueMode ) {
367+ public Object coerceAstValue (GraphqlFieldVisibility fieldVisibility ,
368+ GraphQLType type ,
369+ Value inputValue ,
370+ Map <String , Object > coercedVariables ,
371+ @ Nullable Map <String , NormalizedInputValue > normalizedVariables ,
372+ ValueMode valueMode ,
373+ boolean unwrappingList ) {
374+
373375 if (inputValue instanceof VariableReference ) {
374- return coercedVariables .get (((VariableReference ) inputValue ).getName ());
376+ Map <String , Object > variables = getVariables (coercedVariables , normalizedVariables , valueMode );
377+ Object variableValue = variables .get (((VariableReference ) inputValue ).getName ());
378+ // this is a special case when we have a normalized variable inside a List:
379+ // we just need to the value here, because the whole list itself is already a NormalizedInputValue
380+ if (unwrappingList && variableValue instanceof NormalizedInputValue ) {
381+ return ((NormalizedInputValue ) variableValue ).getValue ();
382+ } else {
383+ return variableValue ;
384+ }
375385 }
376386 if (inputValue instanceof NullValue ) {
377387 return null ;
@@ -380,16 +390,16 @@ private Object coerceValueAst(GraphqlFieldVisibility fieldVisibility,
380390 return parseLiteral (inputValue , ((GraphQLScalarType ) type ).getCoercing (), coercedVariables );
381391 }
382392 if (isNonNull (type )) {
383- return coerceValueAst (fieldVisibility , unwrapOne (type ), inputValue , coercedVariables , normalizedVariables , valueMode );
393+ return coerceAstValue (fieldVisibility , unwrapOne (type ), inputValue , coercedVariables , normalizedVariables , valueMode , unwrappingList );
384394 }
385395 if (type instanceof GraphQLInputObjectType ) {
386- return coerceValueAstForInputObject (fieldVisibility , (GraphQLInputObjectType ) type , (ObjectValue ) inputValue , coercedVariables , normalizedVariables , valueMode );
396+ return coerceAstValueForInputObject (fieldVisibility , (GraphQLInputObjectType ) type , (ObjectValue ) inputValue , coercedVariables , normalizedVariables , valueMode );
387397 }
388398 if (type instanceof GraphQLEnumType ) {
389399 return ((GraphQLEnumType ) type ).parseLiteral (inputValue );
390400 }
391401 if (isList (type )) {
392- return coerceValueAstForList (fieldVisibility , (GraphQLList ) type , inputValue , coercedVariables , normalizedVariables , valueMode );
402+ return coerceAstValueAstForList (fieldVisibility , (GraphQLList ) type , inputValue , coercedVariables , normalizedVariables , valueMode );
393403 }
394404 return null ;
395405 }
@@ -399,30 +409,30 @@ private Object parseLiteral(Value inputValue, Coercing coercing, Map<String, Obj
399409 return coercing .parseLiteral (inputValue , variables );
400410 }
401411
402- private Object coerceValueAstForList (GraphqlFieldVisibility fieldVisibility ,
403- GraphQLList graphQLList ,
404- Value value ,
405- Map <String , Object > coercedVariables ,
406- @ Nullable Map <String , NormalizedInputValue > normalizedVariables ,
407- ValueMode valueMode ) {
412+ private Object coerceAstValueAstForList (GraphqlFieldVisibility fieldVisibility ,
413+ GraphQLList graphQLList ,
414+ Value value ,
415+ Map <String , Object > coercedVariables ,
416+ @ Nullable Map <String , NormalizedInputValue > normalizedVariables ,
417+ ValueMode valueMode ) {
408418 if (value instanceof ArrayValue ) {
409419 ArrayValue arrayValue = (ArrayValue ) value ;
410420 List <Object > result = new ArrayList <>();
411421 for (Value singleValue : arrayValue .getValues ()) {
412- result .add (coerceValueAst (fieldVisibility , graphQLList .getWrappedType (), singleValue , coercedVariables , normalizedVariables , valueMode ));
422+ result .add (coerceAstValue (fieldVisibility , graphQLList .getWrappedType (), singleValue , coercedVariables , normalizedVariables , valueMode , true ));
413423 }
414424 return result ;
415425 } else {
416- return Collections .singletonList (coerceValueAst (fieldVisibility ,
426+ return Collections .singletonList (coerceAstValue (fieldVisibility ,
417427 graphQLList .getWrappedType (),
418428 value ,
419429 coercedVariables ,
420430 normalizedVariables ,
421- valueMode ));
431+ valueMode , true ));
422432 }
423433 }
424434
425- private Object coerceValueAstForInputObject (GraphqlFieldVisibility fieldVisibility ,
435+ private Object coerceAstValueForInputObject (GraphqlFieldVisibility fieldVisibility ,
426436 GraphQLInputObjectType type ,
427437 ObjectValue inputValue ,
428438 Map <String , Object > coercedVariables ,
@@ -462,7 +472,7 @@ private Object coerceValueAstForInputObject(GraphqlFieldVisibility fieldVisibili
462472 } else if (fieldValue instanceof VariableReference ) {
463473 coercedValues .put (fieldName , value );
464474 } else {
465- value = coerceValueAst (fieldVisibility , fieldType , fieldValue , coercedVariables , normalizedVariables , valueMode );
475+ value = coerceAstValue (fieldVisibility , fieldType , fieldValue , coercedVariables , normalizedVariables , valueMode , true );
466476 coercedValues .put (fieldName , newValue (value , fieldType , valueMode ));
467477 }
468478 } else {
0 commit comments