|
3 | 3 | import find from '../polyfills/find';
|
4 | 4 | import { GraphQLError } from '../error/GraphQLError';
|
5 | 5 | import inspect from '../jsutils/inspect';
|
6 |
| -import invariant from '../jsutils/invariant'; |
7 | 6 | import keyMap from '../jsutils/keyMap';
|
8 | 7 | import { coerceValue } from '../utilities/coerceValue';
|
9 | 8 | import { typeFromAST } from '../utilities/typeFromAST';
|
@@ -82,25 +81,19 @@ export function getVariableValues(
|
82 | 81 | ),
|
83 | 82 | );
|
84 | 83 | } else if (hasValue) {
|
85 |
| - if (value === null) { |
86 |
| - // If the explicit value `null` was provided, an entry in the coerced |
87 |
| - // values must exist as the value `null`. |
88 |
| - coercedValues[varName] = null; |
89 |
| - } else { |
90 |
| - // Otherwise, a non-null value was provided, coerce it to the expected |
91 |
| - // type or report an error if coercion fails. |
92 |
| - const coerced = coerceValue(value, varType, varDefNode); |
93 |
| - const coercionErrors = coerced.errors; |
94 |
| - if (coercionErrors) { |
95 |
| - for (const error of coercionErrors) { |
96 |
| - error.message = |
97 |
| - `Variable "$${varName}" got invalid value ${inspect(value)}; ` + |
98 |
| - error.message; |
99 |
| - } |
100 |
| - errors.push(...coercionErrors); |
101 |
| - } else { |
102 |
| - coercedValues[varName] = coerced.value; |
| 84 | + // Otherwise, a non-null value was provided, coerce it to the expected |
| 85 | + // type or report an error if coercion fails. |
| 86 | + const coerced = coerceValue(value, varType, varDefNode); |
| 87 | + const coercionErrors = coerced.errors; |
| 88 | + if (coercionErrors) { |
| 89 | + for (const error of coercionErrors) { |
| 90 | + error.message = |
| 91 | + `Variable "$${varName}" got invalid value ${inspect(value)}; ` + |
| 92 | + error.message; |
103 | 93 | }
|
| 94 | + errors.push(...coercionErrors); |
| 95 | + } else { |
| 96 | + coercedValues[varName] = coerced.value; |
104 | 97 | }
|
105 | 98 | }
|
106 | 99 | }
|
@@ -175,31 +168,18 @@ export function getArgumentValues(
|
175 | 168 | );
|
176 | 169 | }
|
177 | 170 | } else if (hasValue) {
|
178 |
| - if (argumentNode.value.kind === Kind.NULL) { |
179 |
| - // If the explicit value `null` was provided, an entry in the coerced |
180 |
| - // values must exist as the value `null`. |
181 |
| - coercedValues[name] = null; |
182 |
| - } else if (argumentNode.value.kind === Kind.VARIABLE) { |
183 |
| - const variableName = argumentNode.value.name.value; |
184 |
| - invariant(variableValues, 'Must exist for hasValue to be true.'); |
185 |
| - // Note: This does no further checking that this variable is correct. |
186 |
| - // This assumes that this query has been validated and the variable |
187 |
| - // usage here is of the correct type. |
188 |
| - coercedValues[name] = variableValues[variableName]; |
189 |
| - } else { |
190 |
| - const valueNode = argumentNode.value; |
191 |
| - const coercedValue = valueFromAST(valueNode, argType, variableValues); |
192 |
| - if (coercedValue === undefined) { |
193 |
| - // Note: ValuesOfCorrectType validation should catch this before |
194 |
| - // execution. This is a runtime check to ensure execution does not |
195 |
| - // continue with an invalid argument value. |
196 |
| - throw new GraphQLError( |
197 |
| - `Argument "${name}" has invalid value ${print(valueNode)}.`, |
198 |
| - argumentNode.value, |
199 |
| - ); |
200 |
| - } |
201 |
| - coercedValues[name] = coercedValue; |
| 171 | + const valueNode = argumentNode.value; |
| 172 | + const coercedValue = valueFromAST(valueNode, argType, variableValues); |
| 173 | + if (coercedValue === undefined) { |
| 174 | + // Note: ValuesOfCorrectType validation should catch this before |
| 175 | + // execution. This is a runtime check to ensure execution does not |
| 176 | + // continue with an invalid argument value. |
| 177 | + throw new GraphQLError( |
| 178 | + `Argument "${name}" has invalid value ${print(valueNode)}.`, |
| 179 | + argumentNode.value, |
| 180 | + ); |
202 | 181 | }
|
| 182 | + coercedValues[name] = coercedValue; |
203 | 183 | }
|
204 | 184 | }
|
205 | 185 | return coercedValues;
|
|
0 commit comments