12
12
use GraphQL \Language \AST \FragmentSpreadNode ;
13
13
use GraphQL \Language \AST \InlineFragmentNode ;
14
14
use GraphQL \Language \AST \NodeList ;
15
+ use GraphQL \Language \AST \NullValueNode ;
15
16
use GraphQL \Language \AST \VariableNode ;
16
17
use GraphQL \Language \AST \VariableDefinitionNode ;
17
18
use GraphQL \Language \Printer ;
@@ -131,10 +132,16 @@ public static function getArgumentValues($def, $node, $variableValues = null)
131
132
[$ node ]
132
133
);
133
134
}
135
+ } else if ($ argumentNode ->value instanceof NullValueNode) {
136
+ // Explicitly set null values should produce the defaultValue if available
137
+ if ($ argDef ->defaultValueExists ()) {
138
+ $ coercedValues [$ name ] = $ argDef ->defaultValue ;
139
+ }
134
140
} else if ($ argumentNode ->value instanceof VariableNode) {
135
141
$ variableName = $ argumentNode ->value ->name ->value ;
136
142
137
- if ($ variableValues && array_key_exists ($ variableName , $ variableValues )) {
143
+ // Explicitly set null values should produce the defaultValue if available
144
+ if ($ variableValues && array_key_exists ($ variableName , $ variableValues ) && $ variableValues [$ variableName ] !== null ) {
138
145
// Note: this does not check that this variable value is correct.
139
146
// This assumes that this query has been validated and the variable
140
147
// usage here is of the correct type.
@@ -152,6 +159,12 @@ public static function getArgumentValues($def, $node, $variableValues = null)
152
159
} else {
153
160
$ valueNode = $ argumentNode ->value ;
154
161
$ coercedValue = AST ::valueFromAST ($ valueNode , $ argType , $ variableValues );
162
+
163
+ // Explicitly set null values should produce the defaultValue if available
164
+ if ($ coercedValue === null && $ argDef ->defaultValueExists ()) {
165
+ $ coercedValue = $ argDef ->defaultValue ;
166
+ }
167
+
155
168
if ($ coercedValue === $ undefined ) {
156
169
$ errors = DocumentValidator::isValidLiteralValue ($ argType , $ valueNode );
157
170
$ message = !empty ($ errors ) ? ("\n" . implode ("\n" , $ errors )) : '' ;
0 commit comments