diff --git a/src/validation/__tests__/ValuesOfCorrectTypeRule-test.ts b/src/validation/__tests__/ValuesOfCorrectTypeRule-test.ts index 3610fa648b..6f7697a694 100644 --- a/src/validation/__tests__/ValuesOfCorrectTypeRule-test.ts +++ b/src/validation/__tests__/ValuesOfCorrectTypeRule-test.ts @@ -1094,22 +1094,6 @@ describe('Validate: Values of correct type', () => { ]); }); - it('Exactly one nullable variable', () => { - expectErrors(` - query ($string: String) { - complicatedArgs { - oneOfArgField(oneOfArg: { stringField: $string }) - } - } - `).toDeepEqual([ - { - message: - 'Variable "string" must be non-nullable to be used for OneOf Input Object "OneOfInput".', - locations: [{ line: 4, column: 37 }], - }, - ]); - }); - it('More than one field', () => { expectErrors(` { diff --git a/src/validation/__tests__/VariablesInAllowedPositionRule-test.ts b/src/validation/__tests__/VariablesInAllowedPositionRule-test.ts index 6fc3d59c39..ec839d7497 100644 --- a/src/validation/__tests__/VariablesInAllowedPositionRule-test.ts +++ b/src/validation/__tests__/VariablesInAllowedPositionRule-test.ts @@ -370,6 +370,16 @@ describe('Validates OneOf Input Objects', () => { `); }); + it('Undefined variable in oneOf input object', () => { + expectErrors(` + { + complicatedArgs { + oneOfArgField(oneOfArg: { stringField: $undefinedVariable }) + } + } + `).toDeepEqual([]); + }); + it('Forbids one nullable variable', () => { expectErrors(` query ($string: String) { diff --git a/src/validation/rules/ValuesOfCorrectTypeRule.ts b/src/validation/rules/ValuesOfCorrectTypeRule.ts index 3f284d7103..6636e6a552 100644 --- a/src/validation/rules/ValuesOfCorrectTypeRule.ts +++ b/src/validation/rules/ValuesOfCorrectTypeRule.ts @@ -82,13 +82,7 @@ export function ValuesOfCorrectTypeRule( } if (type.isOneOf) { - validateOneOfInputObject( - context, - node, - type, - fieldNodeMap, - variableDefinitions, - ); + validateOneOfInputObject(context, node, type, fieldNodeMap); } }, ObjectField(node) { @@ -185,7 +179,6 @@ function validateOneOfInputObject( node: ObjectValueNode, type: GraphQLInputObjectType, fieldNodeMap: ObjMap, - variableDefinitions: { [key: string]: VariableDefinitionNode }, ): void { const keys = Object.keys(fieldNodeMap); const isNotExactlyOneField = keys.length !== 1; @@ -202,7 +195,6 @@ function validateOneOfInputObject( const value = fieldNodeMap[keys[0]]?.value; const isNullLiteral = !value || value.kind === Kind.NULL; - const isVariable = value?.kind === Kind.VARIABLE; if (isNullLiteral) { context.reportError( @@ -210,21 +202,5 @@ function validateOneOfInputObject( nodes: [node], }), ); - return; - } - - if (isVariable) { - const variableName = value.name.value; - const definition = variableDefinitions[variableName]; - const isNullableVariable = definition.type.kind !== Kind.NON_NULL_TYPE; - - if (isNullableVariable) { - context.reportError( - new GraphQLError( - `Variable "${variableName}" must be non-nullable to be used for OneOf Input Object "${type.name}".`, - { nodes: [node] }, - ), - ); - } } }