You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[#3086 rebased on
main](#3086).
Depends on #3812@leebyron comments from original PR:
> Factors out input validation to reusable functions:
>
> * Introduces `validateInputLiteral` by extracting this behavior from
`ValuesOfCorrectTypeRule`.
> * Introduces `validateInputValue` by extracting this behavior from
`coerceInputValue`
> * Simplifies `coerceInputValue` to return early on validation error
> * Unifies error reporting between `validateInputValue` and
`validateInputLiteral`, causing some error message strings to change,
but error data (eg locations) are preserved.
>
> These two parallel functions will be used to validate default values
>
> Potentially breaking if you rely on the existing behavior of
`coerceInputValue` to call a callback function, as the call signature
has changed. GraphQL behavior should not change, though error messages
are now slightly different.
Note: also breaking if you rely on the default callback function to
throw. Grossly similar behavior is available with
`validateInputValue()`.
Co-authored-by: Lee Byron <lee.byron@robinhood.com>
// A nullable variable in a oneOf field position would be caught at validation-time
230
+
// hence the vague error message here.
231
+
message:
232
+
'Argument "input" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" not to be null.',
233
+
locations: [{line: 3,column: 23}],
234
+
path: ['test'],
235
+
},
236
+
],
237
+
});
238
+
});
239
+
240
+
it('errors with missing variable for field',()=>{
241
+
constquery=`
242
+
query ($a: String) {
243
+
test(input: { a: $a }) {
244
+
a
245
+
b
246
+
}
247
+
}
248
+
`;
249
+
constresult=executeQuery(query,rootValue);
250
+
251
+
expectJSON(result).toDeepEqual({
252
+
data: {
253
+
test: null,
254
+
},
255
+
errors: [
256
+
{
257
+
// A nullable variable in a oneOf field position would be caught at validation-time
258
+
// hence the vague error message here.
259
+
message:
260
+
'Argument "input" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" to provide a runtime value.',
261
+
locations: [{line: 3,column: 23}],
262
+
path: ['test'],
263
+
},
264
+
],
265
+
});
266
+
});
267
+
268
+
it('errors with nulled fragment variable for field',()=>{
// A nullable variable in a oneOf field position would be caught at validation-time
289
+
// hence the vague error message here.
290
+
message:
291
+
'Argument "input" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" not to be null.',
292
+
locations: [{line: 6,column: 23}],
293
+
path: ['test'],
294
+
},
295
+
],
296
+
});
297
+
});
298
+
299
+
it('errors with missing fragment variable for field',()=>{
300
+
constquery=`
301
+
query {
302
+
...TestFragment
303
+
}
304
+
fragment TestFragment($a: String) on Query {
305
+
test(input: { a: $a }) {
306
+
a
307
+
b
308
+
}
309
+
}
310
+
`;
311
+
constresult=executeQuery(query,rootValue);
312
+
313
+
expectJSON(result).toDeepEqual({
314
+
data: {
315
+
test: null,
316
+
},
317
+
errors: [
318
+
{
319
+
// A nullable variable in a oneOf field position would be caught at validation-time
320
+
// hence the vague error message here.
321
+
message:
322
+
'Argument "input" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" to provide a runtime value.',
0 commit comments