Skip to content

Commit cc8a494

Browse files
committed
Improved arguments construction
1 parent ae667f3 commit cc8a494

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

graphene/core/types/objecttype.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ class ObjectType(six.with_metaclass(ObjectTypeMeta, BaseObjectType)):
221221

222222

223223
class Mutation(six.with_metaclass(ObjectTypeMeta, BaseObjectType)):
224+
@classmethod
225+
def _construct_arguments(cls, items):
226+
return ArgumentsGroup(**items)
224227

225228
@classmethod
226229
def _prepare_class(cls):
@@ -231,8 +234,7 @@ def _prepare_class(cls):
231234
items.pop('__doc__', None)
232235
items.pop('__module__', None)
233236
items.pop('__weakref__', None)
234-
arguments = ArgumentsGroup(**items)
235-
cls.add_to_class('arguments', arguments)
237+
cls.add_to_class('arguments', cls._construct_arguments(items))
236238
delattr(cls, 'Input')
237239

238240
@classmethod

graphene/relay/types.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,23 +110,13 @@ class ClientIDMutation(Mutation):
110110
client_mutation_id = String(required=True)
111111

112112
@classmethod
113-
def _prepare_class(cls):
114-
input_class = getattr(cls, 'Input', None)
115-
if input_class:
116-
assert hasattr(
117-
cls, 'mutate_and_get_payload'), 'You have to implement mutate_and_get_payload'
118-
119-
items = dict(vars(input_class))
120-
items.pop('__dict__', None)
121-
items.pop('__doc__', None)
122-
items.pop('__module__', None)
123-
items.pop('__weakref__', None)
124-
new_input_type = type('{}Input'.format(
125-
cls._meta.type_name), (MutationInputType, ), items)
126-
cls.add_to_class('input_type', new_input_type)
127-
arguments = ArgumentsGroup(input=NonNull(new_input_type))
128-
cls.add_to_class('arguments', arguments)
129-
delattr(cls, 'Input')
113+
def _construct_arguments(cls, items):
114+
assert hasattr(
115+
cls, 'mutate_and_get_payload'), 'You have to implement mutate_and_get_payload'
116+
new_input_type = type('{}Input'.format(
117+
cls._meta.type_name), (MutationInputType, ), items)
118+
cls.add_to_class('input_type', new_input_type)
119+
return ArgumentsGroup(input=NonNull(new_input_type))
130120

131121
@classmethod
132122
def mutate(cls, instance, args, info):

0 commit comments

Comments
 (0)