mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-09 08:00:39 +03:00
Refactored InputObjectType
This commit is contained in:
parent
cbf0d8fedd
commit
b6522f393c
|
@ -1,4 +1,4 @@
|
||||||
from .definitions import GrapheneInterfaceType, GrapheneObjectType, GrapheneScalarType, GrapheneEnumType
|
from .definitions import GrapheneInterfaceType, GrapheneObjectType, GrapheneScalarType, GrapheneEnumType, GrapheneInputObjectType
|
||||||
from .utils import values_from_enum
|
from .utils import values_from_enum
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,3 +42,12 @@ def generate_enum(enum):
|
||||||
name=enum._meta.name or enum.__name__,
|
name=enum._meta.name or enum.__name__,
|
||||||
description=enum._meta.description or enum.__doc__,
|
description=enum._meta.description or enum.__doc__,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def generate_inputobjecttype(inputobjecttype):
|
||||||
|
return GrapheneInputObjectType(
|
||||||
|
graphene_type=inputobjecttype,
|
||||||
|
name=inputobjecttype._meta.name or inputobjecttype.__name__,
|
||||||
|
description=inputobjecttype._meta.description or inputobjecttype.__doc__,
|
||||||
|
fields=inputobjecttype._meta.get_fields,
|
||||||
|
)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from graphql import GraphQLObjectType, GraphQLInterfaceType, GraphQLScalarType, GraphQLEnumType
|
from graphql import GraphQLObjectType, GraphQLInterfaceType, GraphQLScalarType, GraphQLEnumType, GraphQLInputObjectType
|
||||||
|
|
||||||
|
|
||||||
class GrapheneGraphQLType(object):
|
class GrapheneGraphQLType(object):
|
||||||
|
@ -35,3 +35,7 @@ class GrapheneScalarType(GrapheneGraphQLType, GraphQLScalarType):
|
||||||
|
|
||||||
class GrapheneEnumType(GrapheneGraphQLType, GraphQLEnumType):
|
class GrapheneEnumType(GrapheneGraphQLType, GraphQLEnumType):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class GrapheneInputObjectType(GrapheneGraphQLType, GraphQLInputObjectType):
|
||||||
|
pass
|
||||||
|
|
|
@ -1,19 +1,15 @@
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from graphql import GraphQLInputObjectType
|
|
||||||
|
|
||||||
from ..utils.copy_fields import copy_fields
|
from ..utils.copy_fields import copy_fields
|
||||||
from ..utils.get_fields import get_fields
|
from ..utils.get_fields import get_fields
|
||||||
from ..utils.is_base_type import is_base_type
|
from ..utils.is_base_type import is_base_type
|
||||||
from .definitions import GrapheneGraphQLType
|
|
||||||
from .field import InputField
|
from .field import InputField
|
||||||
from .objecttype import attrs_without_fields
|
from .objecttype import attrs_without_fields
|
||||||
from .options import Options
|
from .options import Options
|
||||||
from .unmountedtype import UnmountedType
|
from .unmountedtype import UnmountedType
|
||||||
|
|
||||||
|
|
||||||
class GrapheneInputObjectType(GrapheneGraphQLType, GraphQLInputObjectType):
|
from ..generators import generate_inputobjecttype
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class InputObjectTypeMeta(type):
|
class InputObjectTypeMeta(type):
|
||||||
|
@ -39,12 +35,8 @@ class InputObjectTypeMeta(type):
|
||||||
|
|
||||||
if not options.graphql_type:
|
if not options.graphql_type:
|
||||||
fields = copy_fields(InputField, fields, parent=cls)
|
fields = copy_fields(InputField, fields, parent=cls)
|
||||||
options.graphql_type = GrapheneInputObjectType(
|
options.get_fields = lambda: fields
|
||||||
graphene_type=cls,
|
options.graphql_type = generate_inputobjecttype(cls)
|
||||||
name=options.name or cls.__name__,
|
|
||||||
description=options.description or cls.__doc__,
|
|
||||||
fields=fields,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
assert not fields, "Can't mount InputFields in an InputObjectType with a defined graphql_type"
|
assert not fields, "Can't mount InputFields in an InputObjectType with a defined graphql_type"
|
||||||
fields = copy_fields(InputField, options.graphql_type.get_fields(), parent=cls)
|
fields = copy_fields(InputField, options.graphql_type.get_fields(), parent=cls)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user