Skip to content

Commit 7134cab

Browse files
authored
Remove oneof validation from values of correct type (#4453)
Supersedes #4445 Fixes #4443 `VariablesInAllowedPositionRule` already validates this
1 parent 9032db1 commit 7134cab

File tree

3 files changed

+11
-41
lines changed

3 files changed

+11
-41
lines changed

src/validation/__tests__/ValuesOfCorrectTypeRule-test.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,22 +1094,6 @@ describe('Validate: Values of correct type', () => {
10941094
]);
10951095
});
10961096

1097-
it('Exactly one nullable variable', () => {
1098-
expectErrors(`
1099-
query ($string: String) {
1100-
complicatedArgs {
1101-
oneOfArgField(oneOfArg: { stringField: $string })
1102-
}
1103-
}
1104-
`).toDeepEqual([
1105-
{
1106-
message:
1107-
'Variable "string" must be non-nullable to be used for OneOf Input Object "OneOfInput".',
1108-
locations: [{ line: 4, column: 37 }],
1109-
},
1110-
]);
1111-
});
1112-
11131097
it('More than one field', () => {
11141098
expectErrors(`
11151099
{

src/validation/__tests__/VariablesInAllowedPositionRule-test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,16 @@ describe('Validates OneOf Input Objects', () => {
370370
`);
371371
});
372372

373+
it('Undefined variable in oneOf input object', () => {
374+
expectErrors(`
375+
{
376+
complicatedArgs {
377+
oneOfArgField(oneOfArg: { stringField: $undefinedVariable })
378+
}
379+
}
380+
`).toDeepEqual([]);
381+
});
382+
373383
it('Forbids one nullable variable', () => {
374384
expectErrors(`
375385
query ($string: String) {

src/validation/rules/ValuesOfCorrectTypeRule.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,7 @@ export function ValuesOfCorrectTypeRule(
8282
}
8383

8484
if (type.isOneOf) {
85-
validateOneOfInputObject(
86-
context,
87-
node,
88-
type,
89-
fieldNodeMap,
90-
variableDefinitions,
91-
);
85+
validateOneOfInputObject(context, node, type, fieldNodeMap);
9286
}
9387
},
9488
ObjectField(node) {
@@ -185,7 +179,6 @@ function validateOneOfInputObject(
185179
node: ObjectValueNode,
186180
type: GraphQLInputObjectType,
187181
fieldNodeMap: ObjMap<ObjectFieldNode>,
188-
variableDefinitions: { [key: string]: VariableDefinitionNode },
189182
): void {
190183
const keys = Object.keys(fieldNodeMap);
191184
const isNotExactlyOneField = keys.length !== 1;
@@ -202,29 +195,12 @@ function validateOneOfInputObject(
202195

203196
const value = fieldNodeMap[keys[0]]?.value;
204197
const isNullLiteral = !value || value.kind === Kind.NULL;
205-
const isVariable = value?.kind === Kind.VARIABLE;
206198

207199
if (isNullLiteral) {
208200
context.reportError(
209201
new GraphQLError(`Field "${type.name}.${keys[0]}" must be non-null.`, {
210202
nodes: [node],
211203
}),
212204
);
213-
return;
214-
}
215-
216-
if (isVariable) {
217-
const variableName = value.name.value;
218-
const definition = variableDefinitions[variableName];
219-
const isNullableVariable = definition.type.kind !== Kind.NON_NULL_TYPE;
220-
221-
if (isNullableVariable) {
222-
context.reportError(
223-
new GraphQLError(
224-
`Variable "${variableName}" must be non-nullable to be used for OneOf Input Object "${type.name}".`,
225-
{ nodes: [node] },
226-
),
227-
);
228-
}
229205
}
230206
}

0 commit comments

Comments
 (0)