Skip to content

Commit e82c680

Browse files
committed
Added support for Enum Python data structure
1 parent d7e1d9c commit e82c680

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

graphene/core/fields.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import inspect
22
import six
3+
try:
4+
from enum import Enum
5+
except ImportError:
6+
class Enum(object):
7+
pass
38
from functools import total_ordering, wraps
49
from graphql.core.type import (
510
GraphQLField,
@@ -101,8 +106,11 @@ def type_wrapper(self, field_type):
101106

102107
def internal_type(self, schema):
103108
field_type = self.field_type
109+
_is_class = inspect.isclass(field_type)
104110
if isinstance(field_type, Field):
105111
field_type = self.field_type.internal_type(schema)
112+
elif _is_class and issubclass(field_type, Enum):
113+
field_type = enum_to_graphql_enum(field_type)
106114
else:
107115
object_type = self.get_object_type(schema)
108116
if object_type:

graphene/utils/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from .proxy_snake_dict import ProxySnakeDict
33
from .caching import cached_property, memoize
44
from .lazymap import LazyMap
5+
from .misc import enum_to_graphql_enum
56

67
__all__ = ['to_camel_case', 'to_snake_case', 'ProxySnakeDict',
7-
'cached_property', 'memoize', 'LazyMap']
8+
'cached_property', 'memoize', 'LazyMap', 'enum_to_graphql_enum']

0 commit comments

Comments
 (0)