Skip to content

Commit de3b371

Browse files
committed
Fix bug in does_fragment_condition_match (fix #56)
1 parent 5a54530 commit de3b371

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

graphql/core/execution/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def should_include_node(ctx, directives):
167167

168168
def does_fragment_condition_match(ctx, fragment, type_):
169169
conditional_type = type_from_ast(ctx.schema, fragment.type_condition)
170-
if type(conditional_type) == type(type_):
170+
if conditional_type == type_:
171171
return True
172172
if isinstance(conditional_type, (GraphQLInterfaceType, GraphQLUnionType)):
173173
return conditional_type.is_possible_type(type_)

tests/core_execution/test_union_interface.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,25 @@ def test_allows_fragment_conditions_to_be_abstract_types():
247247
{'__typename': 'Dog', 'name': 'Odie', 'barks': True}
248248
]
249249
}
250+
251+
252+
def test_only_include_fields_from_matching_fragment_condition():
253+
ast = parse('''
254+
{
255+
pets { ...PetFields }
256+
}
257+
fragment PetFields on Pet {
258+
__typename
259+
... on Dog {
260+
name
261+
}
262+
}
263+
''')
264+
result = execute(schema, john, ast)
265+
assert not result.errors
266+
assert result.data == {
267+
'pets': [
268+
{'__typename': 'Cat'},
269+
{'__typename': 'Dog', 'name': 'Odie'}
270+
],
271+
}

0 commit comments

Comments
 (0)