Skip to content

Commit 1b9ec8e

Browse files
committed
execute: Forbid to return null from serialize function
Replicates graphql/graphql-js@0fef3c4
1 parent 148e680 commit 1b9ec8e

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/graphql/execution/execute.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -769,10 +769,10 @@ def complete_leaf_value(return_type: GraphQLLeafType, result: Any) -> Any:
769769
serialization is not possible.
770770
"""
771771
serialized_result = return_type.serialize(result)
772-
if serialized_result is Undefined:
772+
if serialized_result is Undefined or serialized_result is None:
773773
raise TypeError(
774-
f"Expected a value of type '{inspect(return_type)}'"
775-
f" but received: {inspect(result)}"
774+
f"Expected `{inspect(return_type)}.serialize({inspect(result)})`"
775+
f" to return non-nullable value, returned: {inspect(serialized_result)}"
776776
)
777777
return serialized_result
778778

tests/execution/test_executor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,8 +983,8 @@ def fails_when_serialize_of_custom_scalar_does_not_return_a_value():
983983
{"customScalar": None},
984984
[
985985
{
986-
"message": "Expected a value of type 'CustomScalar'"
987-
" but received: 'CUSTOM_VALUE'",
986+
"message": "Expected `CustomScalar.serialize('CUSTOM_VALUE')`"
987+
" to return non-nullable value, returned: Undefined",
988988
"locations": [(1, 3)],
989989
"path": ["customScalar"],
990990
}

0 commit comments

Comments
 (0)