Skip to content

Commit 5a92b57

Browse files
committed
Raise error with unexpected enum value
1 parent 828c8ab commit 5a92b57

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

graphql/execution/executor.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,15 @@ def complete_leaf_value(return_type, result):
437437
"""
438438
Complete a Scalar or Enum by serializing to a valid value, returning null if serialization is not possible.
439439
"""
440-
# serialize = getattr(return_type, 'serialize', None)
441-
# assert serialize, 'Missing serialize method on type'
440+
assert hasattr(return_type, 'serialize'), 'Missing serialize method on type'
441+
serialized_result = return_type.serialize(result)
442442

443-
return return_type.serialize(result)
443+
if serialized_result is None:
444+
raise GraphQLError(
445+
('Expected a value of type "{}" but ' +
446+
'received: {}').format(return_type, result)
447+
)
448+
return serialized_result
444449

445450

446451
def complete_abstract_value(exe_context, return_type, field_asts, info, result):

graphql/type/tests/test_enum_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ def test_does_not_accept_values_with_incorrect_casing():
127127
'Expected type "Color", found green.'
128128

129129

130-
# TODO
131130
def test_does_not_accept_incorrect_internal_value():
132131
result = graphql(Schema, '{ colorEnum(fromString: "GREEN") }')
133132
assert result.data == {'colorEnum': None}
134-
assert result.errors[0].messages == ''
133+
assert result.errors[0].message == 'Expected a value of type "Color" ' \
134+
'but received: GREEN'
135135

136136

137137
def test_does_not_accept_internal_value_in_place_of_enum_literal():

0 commit comments

Comments
 (0)