Skip to content

Commit

Permalink
Merge pull request graphql-python#140 from descawed/origin/fix-enums
Browse files Browse the repository at this point in the history
Handle serialization of standard library Enum values
  • Loading branch information
syrusakbary authored Jul 19, 2018
2 parents e2151f9 + 3efd6d1 commit 24687b6
Showing 1 changed file with 4 additions and 1 deletion.
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

0 comments on commit 24687b6

Please sign in to comment.