@@ -451,6 +451,44 @@ class ValuesResolverTest extends Specification {
451451 thrown(GraphQLException )
452452 }
453453
454+ def " coerceVariableValues: use null when variable defined in variableValuesMap is null" () {
455+ given :
456+ def schema = TestUtil . schemaWithInputType(nonNull(GraphQLString ))
457+
458+ def defaultValueForFoo = new StringValue (" defaultValueForFoo" )
459+ VariableDefinition fooVarDef = new VariableDefinition (" foo" , new TypeName (" String" ), defaultValueForFoo)
460+
461+ def defaultValueForBar = new StringValue (" defaultValueForBar" )
462+ VariableDefinition barVarDef = new VariableDefinition (" bar" , new TypeName (" String" ), defaultValueForBar)
463+
464+ def variableValuesMap = [" foo" : null , " bar" : " barValue" ]
465+
466+ when :
467+ def resolvedVars = resolver. coerceVariableValues(schema, [fooVarDef, barVarDef], variableValuesMap)
468+
469+ then :
470+ resolvedVars[' foo' ] == null
471+ resolvedVars[' bar' ] == " barValue"
472+ }
473+
474+ def " coerceVariableValues: if variableType is a Non‐Nullable type and value is null, throw a query error" () {
475+ given :
476+ def schema = TestUtil . schemaWithInputType(nonNull(GraphQLString ))
477+
478+ def defaultValueForFoo = new StringValue (" defaultValueForFoo" )
479+ VariableDefinition fooVarDef = new VariableDefinition (" foo" , new NonNullType (new TypeName (" String" )), defaultValueForFoo)
480+
481+
482+ def variableValuesMap = [" foo" : null ]
483+
484+ when :
485+ resolver. coerceVariableValues(schema, [fooVarDef], variableValuesMap)
486+
487+ then :
488+ def error = thrown(NonNullableValueCoercedAsNullException )
489+ error. message == " Field 'foo' of variable 'foo' has coerced Null value for NonNull type 'String!'"
490+ }
491+
454492 // Note: use NullValue defined in Field when it exists,
455493 // and ignore defaultValue defined in type system
456494 def " getArgumentValues: use null value when argumentValue defined in Field is null" () {
0 commit comments