Skip to content

Commit 6cf4407

Browse files
author
Sam Cooke
committed
Extract completeLeafValue from CompleteValue
Related GraphQL-js commit: graphql/graphql-js@4c5904c
1 parent 546fc28 commit 6cf4407

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

graphql/execution/executor.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,7 @@ def complete_value(self, ctx, return_type, field_asts, info, result):
255255

256256
# If field type is Scalar or Enum, serialize to a valid value, returning null if coercion is not possible.
257257
if isinstance(return_type, (GraphQLScalarType, GraphQLEnumType)):
258-
serialized_result = return_type.serialize(result)
259-
260-
if serialized_result is None:
261-
return None
262-
263-
return serialized_result
258+
return self.complete_leaf_value(ctx, return_type, field_asts, info, result)
264259

265260
runtime_type = None
266261

@@ -318,6 +313,17 @@ def complete_list_value(self, ctx, return_type, field_asts, info, result):
318313

319314
return DeferredList(completed_results) if contains_deferred else completed_results
320315

316+
def complete_leaf_value(self, ctx, return_type, field_asts, info, result):
317+
"""
318+
Complete a Scalar or Enum by serializing to a valid value, returning null if serialization is not possible.
319+
"""
320+
serialized_result = return_type.serialize(result)
321+
322+
if serialized_result is None:
323+
return None
324+
325+
return serialized_result
326+
321327
def resolve_or_error(self, resolve_fn, source, args, info):
322328
curried_resolve_fn = functools.partial(resolve_fn, source, args, info)
323329

0 commit comments

Comments
 (0)