Skip to content

Commit b0e4319

Browse files
committed
Fixed tests
1 parent 54724ec commit b0e4319

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

graphql/execution/experimental/fragment.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
GraphQLObjectType, GraphQLUnionType)
1010
from ..base import ResolveInfo, Undefined, collect_fields, get_field_def
1111
from ..values import get_argument_values
12-
12+
from ...error import GraphQLError
1313

1414
def is_promise(obj):
1515
return isinstance(obj, Promise)
@@ -55,6 +55,7 @@ def get_resolvers(context, type, selection_set):
5555
field_fragment = Fragment(
5656
type=field_base_type,
5757
selection_set=field_ast.selection_set,
58+
info=info,
5859
context=context
5960
)
6061
elif isinstance(field_base_type, (GraphQLInterfaceType, GraphQLUnionType)):
@@ -76,10 +77,11 @@ def get_resolvers(context, type, selection_set):
7677

7778
class Fragment(object):
7879

79-
def __init__(self, type, selection_set, context=None):
80+
def __init__(self, type, selection_set, context=None, info=None):
8081
self.type = type
8182
self.selection_set = selection_set
8283
self.context = context
84+
self.info = info
8385

8486
@cached_property
8587
def partial_resolvers(self):
@@ -89,7 +91,16 @@ def partial_resolvers(self):
8991
self.selection_set
9092
)
9193

94+
def have_type(self, root):
95+
return not self.type.is_type_of or self.type.is_type_of(root, self.context.context_value, self.info)
96+
9297
def resolve(self, root):
98+
if root and not self.have_type(root):
99+
raise GraphQLError(
100+
u'Expected value of type "{}" but got: {}.'.format(self.type, type(root).__name__),
101+
self.info.field_asts
102+
)
103+
93104
contains_promise = False
94105

95106
final_results = OrderedDict()
@@ -98,6 +109,7 @@ def resolve(self, root):
98109
# for field_name, field_resolver, field_args, context, info in self.partial_resolvers)
99110
# )
100111
for response_name, field_resolver, field_args, context, info in self.partial_resolvers:
112+
101113
result = field_resolver(root, field_args, context, info)
102114
if result is Undefined:
103115
continue
@@ -144,7 +156,8 @@ def __eq__(self, other):
144156
return isinstance(other, Fragment) and (
145157
other.type == self.type and
146158
other.selection_set == self.selection_set and
147-
other.context == self.context
159+
other.context == self.context and
160+
other.info == self.info
148161
)
149162

150163

@@ -169,7 +182,7 @@ def get_fragment(self, type):
169182
assert type in self.possible_types, (
170183
'Runtime Object type "{}" is not a possible type for "{}".'
171184
).format(type, self.abstract_type)
172-
self._fragments[type] = Fragment(type, self.selection_set, self.context)
185+
self._fragments[type] = Fragment(type, self.selection_set, self.context, self.info)
173186
return self._fragments[type]
174187

175188
def resolve_type(self, result):

0 commit comments

Comments
 (0)