Improved arguments construction

This commit is contained in:
Syrus Akbary 2015-11-12 23:21:58 -08:00
parent ae667f3915
commit cc8a494753
2 changed files with 11 additions and 19 deletions

View File

@ -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

View File

@ -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):