From cc8a494753574da71515f135b755beb35b62a4c3 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Thu, 12 Nov 2015 23:21:58 -0800 Subject: [PATCH] Improved arguments construction --- graphene/core/types/objecttype.py | 6 ++++-- graphene/relay/types.py | 24 +++++++----------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/graphene/core/types/objecttype.py b/graphene/core/types/objecttype.py index 9745d3c5..27628222 100644 --- a/graphene/core/types/objecttype.py +++ b/graphene/core/types/objecttype.py @@ -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 diff --git a/graphene/relay/types.py b/graphene/relay/types.py index 91bc9210..f1dfacc0 100644 --- a/graphene/relay/types.py +++ b/graphene/relay/types.py @@ -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: - 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') + def _construct_arguments(cls, items): + assert hasattr( + cls, 'mutate_and_get_payload'), 'You have to implement mutate_and_get_payload' + new_input_type = type('{}Input'.format( + cls._meta.type_name), (MutationInputType, ), items) + cls.add_to_class('input_type', new_input_type) + return ArgumentsGroup(input=NonNull(new_input_type)) @classmethod def mutate(cls, instance, args, info):