Skip to content

Commit 2ebb339

Browse files
committed
Add missing test case and cleanup
1 parent f43006d commit 2ebb339

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

graphql/core/validation/rules.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -659,19 +659,19 @@ def effective_type(var_type, var_def):
659659

660660
return GraphQLNonNull(var_type)
661661

662-
@staticmethod
663-
def var_type_allowed_for_type(var_type, expected_type):
662+
@classmethod
663+
def var_type_allowed_for_type(cls, var_type, expected_type):
664664
if isinstance(expected_type, GraphQLNonNull):
665665
if isinstance(var_type, GraphQLNonNull):
666-
return VariablesInAllowedPosition.var_type_allowed_for_type(var_type.of_type, expected_type.of_type)
666+
return cls.var_type_allowed_for_type(var_type.of_type, expected_type.of_type)
667667

668668
return False
669669

670670
if isinstance(var_type, GraphQLNonNull):
671-
return VariablesInAllowedPosition.var_type_allowed_for_type(var_type.of_type, expected_type)
671+
return cls.var_type_allowed_for_type(var_type.of_type, expected_type)
672672

673673
if isinstance(var_type, GraphQLList) and isinstance(expected_type, GraphQLList):
674-
return VariablesInAllowedPosition.var_type_allowed_for_type(var_type.of_type, expected_type.of_type)
674+
return cls.var_type_allowed_for_type(var_type.of_type, expected_type.of_type)
675675

676676
return var_type == expected_type
677677

tests/core_validation/test_variables_in_allowed_position.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,22 @@ def test_non_null_boolean_boolean():
5050
}
5151
''')
5252

53-
def test_int_non_nll_int_with_default():
53+
54+
def test_non_null_boolean_to_boolean_within_fragment():
55+
expect_passes_rule(VariablesInAllowedPosition, '''
56+
fragment booleanArgFrag on ComplicatedArgs {
57+
booleanArgField(booleanArg: $nonNullBooleanArg)
58+
}
59+
query Query($nonNullBooleanArg: Boolean!)
60+
{
61+
complicatedArgs {
62+
...booleanArgFrag
63+
}
64+
}
65+
''')
66+
67+
68+
def test_int_non_null_int_with_default():
5469
expect_passes_rule(VariablesInAllowedPosition, '''
5570
query Query($intArg: Int = 1)
5671
{
@@ -230,4 +245,4 @@ def test_string_non_null_boolean_in_directive():
230245
''', [
231246
{ 'message': VariablesInAllowedPosition.bad_var_pos_message('stringVar', 'String', 'Boolean!'),
232247
'locations': [SourceLocation(4, 26)] }
233-
])
248+
])

0 commit comments

Comments
 (0)