Skip to content

Commit b32af06

Browse files
test(validation): add OneOf variable tests from 16.x.x to next (#4581)
PRs from `16.x.x`: - #4363 - #4453 missing from PR on `next`: - #4194 Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>
1 parent 1922d0d commit b32af06

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/validation/__tests__/VariablesInAllowedPositionRule-test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,3 +493,44 @@ describe('Validate: Variables are in allowed positions', () => {
493493
});
494494
});
495495
});
496+
497+
describe('Validates OneOf Input Objects', () => {
498+
it('Allows exactly one non-nullable variable', () => {
499+
expectValid(`
500+
query ($string: String!) {
501+
complicatedArgs {
502+
oneOfArgField(oneOfArg: { stringField: $string })
503+
}
504+
}
505+
`);
506+
});
507+
508+
it('Undefined variable in oneOf input object', () => {
509+
expectErrors(`
510+
{
511+
complicatedArgs {
512+
oneOfArgField(oneOfArg: { stringField: $undefinedVariable })
513+
}
514+
}
515+
`).toDeepEqual([]);
516+
});
517+
518+
it('Forbids one nullable variable', () => {
519+
expectErrors(`
520+
query ($string: String) {
521+
complicatedArgs {
522+
oneOfArgField(oneOfArg: { stringField: $string })
523+
}
524+
}
525+
`).toDeepEqual([
526+
{
527+
message:
528+
'Variable "$string" is of type "String" but must be non-nullable to be used for OneOf Input Object "OneOfInput".',
529+
locations: [
530+
{ line: 2, column: 14 },
531+
{ line: 4, column: 50 },
532+
],
533+
},
534+
]);
535+
});
536+
});

0 commit comments

Comments
 (0)