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