Added support for Enum Python data structure

This commit is contained in:
Syrus Akbary 2015-10-28 01:27:32 -07:00
parent d7e1d9c598
commit e82c680fd1
2 changed files with 10 additions and 1 deletions

View File

@ -1,5 +1,10 @@
import inspect import inspect
import six import six
try:
from enum import Enum
except ImportError:
class Enum(object):
pass
from functools import total_ordering, wraps from functools import total_ordering, wraps
from graphql.core.type import ( from graphql.core.type import (
GraphQLField, GraphQLField,
@ -101,8 +106,11 @@ class Field(object):
def internal_type(self, schema): def internal_type(self, schema):
field_type = self.field_type field_type = self.field_type
_is_class = inspect.isclass(field_type)
if isinstance(field_type, Field): if isinstance(field_type, Field):
field_type = self.field_type.internal_type(schema) field_type = self.field_type.internal_type(schema)
elif _is_class and issubclass(field_type, Enum):
field_type = enum_to_graphql_enum(field_type)
else: else:
object_type = self.get_object_type(schema) object_type = self.get_object_type(schema)
if object_type: if object_type:

View File

@ -2,6 +2,7 @@ from .str_converters import to_camel_case, to_snake_case
from .proxy_snake_dict import ProxySnakeDict from .proxy_snake_dict import ProxySnakeDict
from .caching import cached_property, memoize from .caching import cached_property, memoize
from .lazymap import LazyMap from .lazymap import LazyMap
from .misc import enum_to_graphql_enum
__all__ = ['to_camel_case', 'to_snake_case', 'ProxySnakeDict', __all__ = ['to_camel_case', 'to_snake_case', 'ProxySnakeDict',
'cached_property', 'memoize', 'LazyMap'] 'cached_property', 'memoize', 'LazyMap', 'enum_to_graphql_enum']