Skip to content

Handle serialization of standard library Enum values #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion graphql/type/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from ..language import ast
from ..pyutils.cached_property import cached_property
from ..pyutils.ordereddict import OrderedDict
from ..pyutils.compat import Enum as PyEnum
from ..utils.assert_valid_name import assert_valid_name
from ..utils.undefined import Undefined

Expand Down Expand Up @@ -516,9 +517,11 @@ def get_value(self, name):

def serialize(self, value):
# type: (str) -> Optional[str]
if isinstance(value, PyEnum):
# We handle PyEnum values
value = value.value
if isinstance(value, collections.Hashable):
enum_value = self._value_lookup.get(value)

if enum_value:
return enum_value.name

Expand Down