Skip to content

Commit 21a7e93

Browse files
committed
Remove oneof validation from values of correct type
Replicates graphql/graphql-js@7134cab
1 parent 9fbc42f commit 21a7e93

3 files changed

Lines changed: 14 additions & 41 deletions

File tree

src/graphql/validation/rules/values_of_correct_type.py

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
from typing import cast, Any, Dict, Mapping
1+
from typing import cast, Any, Mapping
22

33
from ...error import GraphQLError
44
from ...language import (
55
BooleanValueNode,
66
EnumValueNode,
77
FloatValueNode,
88
IntValueNode,
9-
NonNullTypeNode,
109
NullValueNode,
1110
ListValueNode,
1211
ObjectFieldNode,
1312
ObjectValueNode,
1413
StringValueNode,
1514
ValueNode,
1615
VariableDefinitionNode,
17-
VariableNode,
1816
VisitorAction,
1917
SKIP,
2018
print_ast,
@@ -86,9 +84,7 @@ def enter_object_value(self, node: ObjectValueNode, *_args: Any) -> VisitorActio
8684
)
8785
)
8886
if type_.is_one_of:
89-
validate_one_of_input_object(
90-
self.context, node, type_, field_node_map, self.variable_definitions
91-
)
87+
validate_one_of_input_object(self.context, node, type_, field_node_map)
9288
return None
9389

9490
def enter_object_field(self, node: ObjectFieldNode, *_args: Any) -> None:
@@ -187,7 +183,6 @@ def validate_one_of_input_object(
187183
node: ObjectValueNode,
188184
type_: GraphQLInputObjectType,
189185
field_node_map: Mapping[str, ObjectFieldNode],
190-
variable_definitions: Dict[str, VariableDefinitionNode],
191186
) -> None:
192187
keys = list(field_node_map)
193188
is_not_exactly_one_filed = len(keys) != 1
@@ -212,19 +207,3 @@ def validate_one_of_input_object(
212207
node,
213208
)
214209
)
215-
return
216-
217-
is_variable = value and isinstance(value, VariableNode)
218-
if is_variable:
219-
variable_name = cast(VariableNode, value).name.value
220-
definition = variable_definitions[variable_name]
221-
is_nullable_variable = not isinstance(definition.type, NonNullTypeNode)
222-
223-
if is_nullable_variable:
224-
context.report_error(
225-
GraphQLError(
226-
f"Variable '{variable_name}' must be non-nullable"
227-
f" to be used for OneOf Input Object '{type_.name}'.",
228-
node,
229-
)
230-
)

tests/validation/test_values_of_correct_type.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,24 +1085,6 @@ def exactly_one_null_field():
10851085
],
10861086
)
10871087

1088-
def exactly_one_nullable_variable():
1089-
assert_errors(
1090-
"""
1091-
query ($string: String) {
1092-
complicatedArgs {
1093-
oneOfArgField(oneOfArg: { stringField: $string })
1094-
}
1095-
}
1096-
""",
1097-
[
1098-
{
1099-
"message": "Variable 'string' must be non-nullable to be used"
1100-
" for OneOf Input Object 'OneOfInput'.",
1101-
"locations": [(4, 45)],
1102-
},
1103-
],
1104-
)
1105-
11061088
def more_than_one_field():
11071089
assert_errors(
11081090
"""

tests/validation/test_variables_in_allowed_position.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,18 @@ def allows_exactly_one_non_nullable_variable():
344344
}
345345
""")
346346

347+
def undefined_variable_in_one_of_input_object():
348+
assert_errors(
349+
"""
350+
{
351+
complicatedArgs {
352+
oneOfArgField(oneOfArg: { stringField: $undefinedVariable })
353+
}
354+
}
355+
""",
356+
[],
357+
)
358+
347359
def forbids_one_nullable_variable():
348360
assert_errors(
349361
"""

0 commit comments

Comments
 (0)