Improved Relay Mutation

This commit is contained in:
Syrus Akbary 2017-07-24 23:09:52 -07:00
parent 7ca5c2225f
commit ed4bcce0cf

View File

@ -14,7 +14,10 @@ class ClientIDMutation(Mutation):
abstract = True abstract = True
@classmethod @classmethod
def __init_subclass_with_meta__(cls, output=None, arguments=None, name=None, **options): def __init_subclass_with_meta__(cls, output=None, input_fields=None, arguments=None, name=None, abstract=False, **options):
if abstract:
return
input_class = getattr(cls, 'Input', None) input_class = getattr(cls, 'Input', None)
name = name or cls.__name__ name = name or cls.__name__
base_name = re.sub('Payload$', '', name) base_name = re.sub('Payload$', '', name)
@ -25,11 +28,15 @@ class ClientIDMutation(Mutation):
bases = (InputObjectType, ) bases = (InputObjectType, )
if input_class: if input_class:
bases += (input_class, ) bases += (input_class, )
if not input_fields:
input_fields = {}
cls.Input = type('{}Input'.format(base_name), cls.Input = type(
bases, { '{}Input'.format(base_name),
'client_mutation_id': String(name='clientMutationId') bases,
}) OrderedDict(input_fields, client_mutation_id=String(name='clientMutationId'))
)
arguments = OrderedDict( arguments = OrderedDict(
input=cls.Input(required=True) input=cls.Input(required=True)