From b7604df3869dcd33e248bc9e29ddcc326680b99e Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Fri, 20 Feb 2026 09:20:45 +0200 Subject: [PATCH] test(validation): add OneOf variable tests from 16.x.x to next - #4363 and #4453 on 16.x.x had some tests missing from #4194 on next --- .../VariablesInAllowedPositionRule-test.ts | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/validation/__tests__/VariablesInAllowedPositionRule-test.ts b/src/validation/__tests__/VariablesInAllowedPositionRule-test.ts index 127f146230..f1396e9186 100644 --- a/src/validation/__tests__/VariablesInAllowedPositionRule-test.ts +++ b/src/validation/__tests__/VariablesInAllowedPositionRule-test.ts @@ -493,3 +493,44 @@ describe('Validate: Variables are in allowed positions', () => { }); }); }); + +describe('Validates OneOf Input Objects', () => { + it('Allows exactly one non-nullable variable', () => { + expectValid(` + query ($string: String!) { + complicatedArgs { + oneOfArgField(oneOfArg: { stringField: $string }) + } + } + `); + }); + + it('Undefined variable in oneOf input object', () => { + expectErrors(` + { + complicatedArgs { + oneOfArgField(oneOfArg: { stringField: $undefinedVariable }) + } + } + `).toDeepEqual([]); + }); + + it('Forbids one nullable variable', () => { + expectErrors(` + query ($string: String) { + complicatedArgs { + oneOfArgField(oneOfArg: { stringField: $string }) + } + } + `).toDeepEqual([ + { + message: + 'Variable "$string" is of type "String" but must be non-nullable to be used for OneOf Input Object "OneOfInput".', + locations: [ + { line: 2, column: 14 }, + { line: 4, column: 50 }, + ], + }, + ]); + }); +});