Skip to content

Commit 546fc28

Browse files
author
Sam Cooke
committed
Extract completeListValue funciton from CompleteValue
Related GraphQL-js commit: graphql/graphql-js@ab77470
1 parent 2528d1d commit 546fc28

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

graphql/execution/executor.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -251,21 +251,7 @@ def complete_value(self, ctx, return_type, field_asts, info, result):
251251

252252
# If field type is List, complete each item in the list with the inner type
253253
if isinstance(return_type, GraphQLList):
254-
assert isinstance(result, collections.Iterable), \
255-
('User Error: expected iterable, but did not find one' +
256-
'for field {}.{}').format(info.parent_type, info.field_name)
257-
258-
item_type = return_type.of_type
259-
completed_results = []
260-
contains_deferred = False
261-
for item in result:
262-
completed_item = self.complete_value_catching_error(ctx, item_type, field_asts, info, item)
263-
if not contains_deferred and isinstance(completed_item, Deferred):
264-
contains_deferred = True
265-
266-
completed_results.append(completed_item)
267-
268-
return DeferredList(completed_results) if contains_deferred else completed_results
254+
return self.complete_list_value(ctx, return_type, field_asts, info, result)
269255

270256
# If field type is Scalar or Enum, serialize to a valid value, returning null if coercion is not possible.
271257
if isinstance(return_type, (GraphQLScalarType, GraphQLEnumType)):
@@ -312,6 +298,26 @@ def complete_value(self, ctx, return_type, field_asts, info, result):
312298

313299
return self._execute_fields(ctx, runtime_type, result, subfield_asts)
314300

301+
def complete_list_value(self, ctx, return_type, field_asts, info, result):
302+
"""
303+
Complete a list value by completing each item in the list with the inner type
304+
"""
305+
assert isinstance(result, collections.Iterable), \
306+
('User Error: expected iterable, but did not find one' +
307+
'for field {}.{}').format(info.parent_type, info.field_name)
308+
309+
item_type = return_type.of_type
310+
completed_results = []
311+
contains_deferred = False
312+
for item in result:
313+
completed_item = self.complete_value_catching_error(ctx, item_type, field_asts, info, item)
314+
if not contains_deferred and isinstance(completed_item, Deferred):
315+
contains_deferred = True
316+
317+
completed_results.append(completed_item)
318+
319+
return DeferredList(completed_results) if contains_deferred else completed_results
320+
315321
def resolve_or_error(self, resolve_fn, source, args, info):
316322
curried_resolve_fn = functools.partial(resolve_fn, source, args, info)
317323

0 commit comments

Comments
 (0)