Skip to content

Commit b356f66

Browse files
committed
Fixed tests
1 parent 54724ec commit b356f66

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

graphql/execution/experimental/fragment.py

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

1314

1415
def is_promise(obj):
@@ -55,6 +56,7 @@ def get_resolvers(context, type, selection_set):
5556
field_fragment = Fragment(
5657
type=field_base_type,
5758
selection_set=field_ast.selection_set,
59+
info=info,
5860
context=context
5961
)
6062
elif isinstance(field_base_type, (GraphQLInterfaceType, GraphQLUnionType)):
@@ -76,10 +78,11 @@ def get_resolvers(context, type, selection_set):
7678

7779
class Fragment(object):
7880

79-
def __init__(self, type, selection_set, context=None):
81+
def __init__(self, type, selection_set, context=None, info=None):
8082
self.type = type
8183
self.selection_set = selection_set
8284
self.context = context
85+
self.info = info
8386

8487
@cached_property
8588
def partial_resolvers(self):
@@ -89,7 +92,16 @@ def partial_resolvers(self):
8992
self.selection_set
9093
)
9194

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

95107
final_results = OrderedDict()
@@ -98,6 +110,7 @@ def resolve(self, root):
98110
# for field_name, field_resolver, field_args, context, info in self.partial_resolvers)
99111
# )
100112
for response_name, field_resolver, field_args, context, info in self.partial_resolvers:
113+
101114
result = field_resolver(root, field_args, context, info)
102115
if result is Undefined:
103116
continue
@@ -144,7 +157,8 @@ def __eq__(self, other):
144157
return isinstance(other, Fragment) and (
145158
other.type == self.type and
146159
other.selection_set == self.selection_set and
147-
other.context == self.context
160+
other.context == self.context and
161+
other.info == self.info
148162
)
149163

150164

@@ -169,7 +183,7 @@ def get_fragment(self, type):
169183
assert type in self.possible_types, (
170184
'Runtime Object type "{}" is not a possible type for "{}".'
171185
).format(type, self.abstract_type)
172-
self._fragments[type] = Fragment(type, self.selection_set, self.context)
186+
self._fragments[type] = Fragment(type, self.selection_set, self.context, self.info)
173187
return self._fragments[type]
174188

175189
def resolve_type(self, result):

0 commit comments

Comments
 (0)