Skip to content

Commit cd55555

Browse files
committed
Avoid crash when oneOf input variable is not defined
1 parent ba4b411 commit cd55555

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/validation/__tests__/ValuesOfCorrectTypeRule-test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,19 @@ describe('Validate: Values of correct type', () => {
11251125
},
11261126
]);
11271127
});
1128+
1129+
it('Undefined variable in oneOf input object', () => {
1130+
// This test verifies that undefined variables in OneOf input objects
1131+
// don't cause a TypeError in ValuesOfCorrectTypeRule.
1132+
// The undefined variable should be caught by NoUndefinedVariablesRule instead.
1133+
expectErrors(`
1134+
{
1135+
complicatedArgs {
1136+
oneOfArgField(oneOfArg: { stringField: $undefinedVariable })
1137+
}
1138+
}
1139+
`).toDeepEqual([]);
1140+
});
11281141
});
11291142

11301143
describe('Directive arguments', () => {

src/validation/rules/ValuesOfCorrectTypeRule.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@ function validateOneOfInputObject(
216216
if (isVariable) {
217217
const variableName = value.name.value;
218218
const definition = variableDefinitions[variableName];
219+
220+
// If the variable definition is missing, skip validation here.
221+
// This should be caught by other validation rules.
222+
if (!definition) {
223+
return;
224+
}
225+
219226
const isNullableVariable = definition.type.kind !== Kind.NON_NULL_TYPE;
220227

221228
if (isNullableVariable) {

0 commit comments

Comments
 (0)