Skip to content

Commit b7604df

Browse files
JoviDeCroockyaacovCR
authored andcommitted
test(validation): add OneOf variable tests from 16.x.x to next
- graphql#4363 and graphql#4453 on 16.x.x had some tests missing from graphql#4194 on next
1 parent 43a0d9f commit b7604df

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

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)