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
Re-use all existing validation, updating (or updating tests for):
- ProvidedRequiredArguments
- ValuesOfCorrectType
- VariablesAreInputTypes
- UniqueVariableNames
- VariablesInAllowedPosition
Some of the implications here I'm not in love with: I think it's become more clear that fragment arguments ought to be ArgumentDefinitionNodes rather than VariableDefinitionNodes, even though when *used* they are still variables.
I'll try redoing this PR using ArgumentDefinitionNode and see how that simplifies or complicates the matter
// We could differentiate between required/optional (i.e. no default value)
374
+
// vs. nullable/non-nullable (i.e. no !), whereas now they are conflated.
375
+
// So today:
376
+
// $x: Int! `x:` is required and must not be null (NOT a nullable variable)
377
+
// $x: Int! = 3 `x:` is not required and must not be null (MAY BE a nullable variable)
378
+
// $x: Int `x:` is not required and may be null
379
+
// $x: Int = 3 `x:` is not required and may be null
380
+
//
381
+
// It feels weird to collapse the nullable cases but not the non-nullable ones.
382
+
// Whereas all four feel like they ought to mean something explicitly different.
383
+
//
384
+
// Potential proposal:
385
+
// $x: Int! `x:` is required and must not be null (NOT a nullable variable)
386
+
// $x: Int! = 3 `x:` is not required and must not be null (NOT a nullable variable)
387
+
// $x: Int `x:` is required and may be null
388
+
// $x: Int = 3 `x:` is not required and may be null
389
+
//
390
+
// Required then is whether there's a default value,
391
+
// and nullable is whether there's a !
392
+
it('Missing nullable argument with default is allowed',()=>{
393
+
expectValid(`
394
+
{
395
+
...F
396
+
397
+
}
398
+
fragment F($x: Int = 3) on Query {
399
+
foo
400
+
}
401
+
`);
402
+
});
403
+
// Above proposal: this should be an error
404
+
it('Missing nullable argument is allowed',()=>{
405
+
expectValid(`
406
+
{
407
+
...F
408
+
409
+
}
410
+
fragment F($x: Int) on Query {
411
+
foo
412
+
}
413
+
`);
414
+
});
415
+
it('Missing non-nullable argument with default is allowed',()=>{
416
+
expectValid(`
417
+
{
418
+
...F
419
+
420
+
}
421
+
fragment F($x: Int! = 3) on Query {
422
+
foo
423
+
}
424
+
`);
425
+
});
426
+
it('Missing non-nullable argument is not allowed',()=>{
427
+
expectErrors(`
428
+
{
429
+
...F
430
+
431
+
}
432
+
fragment F($x: Int!) on Query {
433
+
foo
434
+
}
435
+
`).toDeepEqual([
436
+
{
437
+
message:
438
+
'Fragment "F" argument "x" of type "{ kind: "NonNullType", type: { kind: "NamedType", name: [Object], loc: [Object] }, loc: [Object] }" is required, but it was not provided.',
0 commit comments