diff --git a/src/validation/__tests__/ValuesOfCorrectTypeRule-test.ts b/src/validation/__tests__/ValuesOfCorrectTypeRule-test.ts index 3610fa648b..339ce4d219 100644 --- a/src/validation/__tests__/ValuesOfCorrectTypeRule-test.ts +++ b/src/validation/__tests__/ValuesOfCorrectTypeRule-test.ts @@ -1125,6 +1125,19 @@ describe('Validate: Values of correct type', () => { }, ]); }); + + it('Undefined variable in oneOf input object', () => { + // This test verifies that undefined variables in OneOf input objects + // don't cause a TypeError in ValuesOfCorrectTypeRule. + // The undefined variable should be caught by NoUndefinedVariablesRule instead. + expectErrors(` + { + complicatedArgs { + oneOfArgField(oneOfArg: { stringField: $undefinedVariable }) + } + } + `).toDeepEqual([]); + }); }); describe('Directive arguments', () => { diff --git a/src/validation/rules/ValuesOfCorrectTypeRule.ts b/src/validation/rules/ValuesOfCorrectTypeRule.ts index 3f284d7103..e6e83be729 100644 --- a/src/validation/rules/ValuesOfCorrectTypeRule.ts +++ b/src/validation/rules/ValuesOfCorrectTypeRule.ts @@ -216,6 +216,13 @@ function validateOneOfInputObject( if (isVariable) { const variableName = value.name.value; const definition = variableDefinitions[variableName]; + + // If the variable definition is missing, skip validation here. + // This should be caught by other validation rules. + if (!definition) { + return; + } + const isNullableVariable = definition.type.kind !== Kind.NON_NULL_TYPE; if (isNullableVariable) {