mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-23 01:56:54 +03:00
Simplified InputObjectType
This commit is contained in:
parent
5ee6e2b8e7
commit
d8b42dd1ca
|
@ -1,45 +1,17 @@
|
|||
import six
|
||||
from collections import OrderedDict
|
||||
|
||||
from ..utils.is_base_type import is_base_type
|
||||
from ..utils.trim_docstring import trim_docstring
|
||||
from .abstracttype import AbstractTypeMeta
|
||||
from .inputfield import InputField
|
||||
from .options import Options
|
||||
from .unmountedtype import UnmountedType
|
||||
from .utils import get_base_fields, merge, yank_fields_from_attrs
|
||||
from .utils import yank_fields_from_attrs
|
||||
|
||||
from .base import BaseOptions, BaseType
|
||||
|
||||
|
||||
class InputObjectTypeMeta(AbstractTypeMeta):
|
||||
|
||||
def __new__(cls, name, bases, attrs):
|
||||
# Also ensure initialization is only performed for subclasses of
|
||||
# InputObjectType
|
||||
if not is_base_type(bases, InputObjectTypeMeta):
|
||||
return type.__new__(cls, name, bases, attrs)
|
||||
|
||||
options = Options(
|
||||
attrs.pop('Meta', None),
|
||||
name=name,
|
||||
description=trim_docstring(attrs.get('__doc__')),
|
||||
local_fields=None,
|
||||
)
|
||||
|
||||
options.base_fields = get_base_fields(bases, _as=InputField)
|
||||
|
||||
if not options.local_fields:
|
||||
options.local_fields = yank_fields_from_attrs(attrs, _as=InputField)
|
||||
|
||||
options.fields = merge(
|
||||
options.base_fields,
|
||||
options.local_fields
|
||||
)
|
||||
return type.__new__(cls, name, bases, dict(attrs, _meta=options))
|
||||
|
||||
def __str__(cls): # noqa: N802
|
||||
return cls._meta.name
|
||||
class InputObjectTypeOptions(BaseOptions):
|
||||
fields = None # type: Dict[str, Field]
|
||||
|
||||
|
||||
class InputObjectType(six.with_metaclass(InputObjectTypeMeta, UnmountedType)):
|
||||
class InputObjectType(UnmountedType, BaseType):
|
||||
'''
|
||||
Input Object Type Definition
|
||||
|
||||
|
@ -49,6 +21,19 @@ class InputObjectType(six.with_metaclass(InputObjectTypeMeta, UnmountedType)):
|
|||
Using `NonNull` will ensure that a value must be provided by the query
|
||||
'''
|
||||
|
||||
@classmethod
|
||||
def __init_subclass_with_meta__(cls, **options):
|
||||
_meta = InputObjectTypeOptions(cls)
|
||||
|
||||
fields = OrderedDict()
|
||||
for base in reversed(cls.__mro__):
|
||||
fields.update(
|
||||
yank_fields_from_attrs(base.__dict__, _as=InputField)
|
||||
)
|
||||
|
||||
_meta.fields = fields
|
||||
super(InputObjectType, cls).__init_subclass_with_meta__(_meta=_meta, **options)
|
||||
|
||||
@classmethod
|
||||
def get_type(cls):
|
||||
'''
|
||||
|
|
Loading…
Reference in New Issue
Block a user