mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-29 13:03:56 +03:00
Improved arguments construction
This commit is contained in:
parent
ae667f3915
commit
cc8a494753
|
@ -221,6 +221,9 @@ class ObjectType(six.with_metaclass(ObjectTypeMeta, BaseObjectType)):
|
|||
|
||||
|
||||
class Mutation(six.with_metaclass(ObjectTypeMeta, BaseObjectType)):
|
||||
@classmethod
|
||||
def _construct_arguments(cls, items):
|
||||
return ArgumentsGroup(**items)
|
||||
|
||||
@classmethod
|
||||
def _prepare_class(cls):
|
||||
|
@ -231,8 +234,7 @@ class Mutation(six.with_metaclass(ObjectTypeMeta, BaseObjectType)):
|
|||
items.pop('__doc__', None)
|
||||
items.pop('__module__', None)
|
||||
items.pop('__weakref__', None)
|
||||
arguments = ArgumentsGroup(**items)
|
||||
cls.add_to_class('arguments', arguments)
|
||||
cls.add_to_class('arguments', cls._construct_arguments(items))
|
||||
delattr(cls, 'Input')
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -110,23 +110,13 @@ class ClientIDMutation(Mutation):
|
|||
client_mutation_id = String(required=True)
|
||||
|
||||
@classmethod
|
||||
def _prepare_class(cls):
|
||||
input_class = getattr(cls, 'Input', None)
|
||||
if input_class:
|
||||
def _construct_arguments(cls, items):
|
||||
assert hasattr(
|
||||
cls, 'mutate_and_get_payload'), 'You have to implement mutate_and_get_payload'
|
||||
|
||||
items = dict(vars(input_class))
|
||||
items.pop('__dict__', None)
|
||||
items.pop('__doc__', None)
|
||||
items.pop('__module__', None)
|
||||
items.pop('__weakref__', None)
|
||||
new_input_type = type('{}Input'.format(
|
||||
cls._meta.type_name), (MutationInputType, ), items)
|
||||
cls.add_to_class('input_type', new_input_type)
|
||||
arguments = ArgumentsGroup(input=NonNull(new_input_type))
|
||||
cls.add_to_class('arguments', arguments)
|
||||
delattr(cls, 'Input')
|
||||
return ArgumentsGroup(input=NonNull(new_input_type))
|
||||
|
||||
@classmethod
|
||||
def mutate(cls, instance, args, info):
|
||||
|
|
Loading…
Reference in New Issue
Block a user