@@ -214,6 +214,8 @@ def complete_value(self, ctx, return_type, field_asts, info, result):
214
214
If the field type is a Scalar or Enum, ensures the completed value is a legal value of the type by calling the
215
215
`serialize` method of GraphQL type definition.
216
216
217
+ If the field is an abstract type, determine the runtime type of the value and then complete based on that type.
218
+
217
219
Otherwise, the field type expects a sub-selection set, and will complete the value by evaluating all
218
220
sub-selections.
219
221
"""
@@ -260,21 +262,11 @@ def complete_value(self, ctx, return_type, field_asts, info, result):
260
262
if isinstance (return_type , GraphQLObjectType ):
261
263
return self .complete_object_value (ctx , return_type , field_asts , info , result )
262
264
263
- # Field type must be Object, Interface or Union and expect sub-selections.
264
- runtime_type = None
265
-
266
265
if isinstance (return_type , (GraphQLInterfaceType , GraphQLUnionType )):
267
- runtime_type = return_type .resolve_type (result , info )
268
- if runtime_type and not return_type .is_possible_type (runtime_type ):
269
- raise GraphQLError (
270
- u'Runtime Object type "{}" is not a possible type for "{}".' .format (runtime_type , return_type ),
271
- field_asts
272
- )
273
-
274
- if not runtime_type :
275
- return None
266
+ return self .complete_abstract_value (ctx , return_type , field_asts , info , result )
276
267
277
- return self .complete_object_value (ctx , runtime_type , field_asts , info , result )
268
+ # Not reachable
269
+ return None
278
270
279
271
def complete_list_value (self , ctx , return_type , field_asts , info , result ):
280
272
"""
@@ -330,6 +322,27 @@ def complete_object_value(self, ctx, return_type, field_asts, info, result):
330
322
331
323
return self ._execute_fields (ctx , return_type , result , subfield_asts )
332
324
325
+ def complete_abstract_value (self , ctx , return_type , field_asts , info , result ):
326
+ """
327
+ Complete an value of an abstract type by determining the runtime type of that value, then completing based
328
+ on that type.
329
+ """
330
+ # Field type must be Object, Interface or Union and expect sub-selections.
331
+ runtime_type = None
332
+
333
+ if isinstance (return_type , (GraphQLInterfaceType , GraphQLUnionType )):
334
+ runtime_type = return_type .resolve_type (result , info )
335
+ if runtime_type and not return_type .is_possible_type (runtime_type ):
336
+ raise GraphQLError (
337
+ u'Runtime Object type "{}" is not a possible type for "{}".' .format (runtime_type , return_type ),
338
+ field_asts
339
+ )
340
+
341
+ if not runtime_type :
342
+ return None
343
+
344
+ return self .complete_object_value (ctx , runtime_type , field_asts , info , result )
345
+
333
346
def resolve_or_error (self , resolve_fn , source , args , info ):
334
347
curried_resolve_fn = functools .partial (resolve_fn , source , args , info )
335
348
0 commit comments