1
+ import functools
1
2
from graphql .core .type import GraphQLField , GraphQLNonNull
2
3
from graphql .core .type .definition import GraphQLArgument
3
4
@@ -17,8 +18,11 @@ def __new__(mcs, name, bases, attrs):
17
18
assert output and not hasattr (output , 'T' ), 'A mutation must define a class named "Output" inside of it that ' \
18
19
'does not subclass an R.ObjectType'
19
20
20
- Input = type (name + 'Input' , (registry .InputType ,), dict (vars (input )))
21
- Output = type (name + 'Payload' , (registry .ObjectType ,), dict (vars (output )))
21
+ input_attrs = mcs ._process_input_attrs (registry , dict (vars (input )))
22
+ output_attrs = mcs ._process_output_attrs (registry , dict (vars (output )))
23
+
24
+ Input = type (name + 'Input' , (registry .InputType ,), input_attrs )
25
+ Output = type (name + 'Payload' , (registry .ObjectType ,), output_attrs )
22
26
attrs ['Input' ] = Input
23
27
attrs ['Output' ] = Output
24
28
@@ -36,7 +40,7 @@ def __new__(mcs, name, bases, attrs):
36
40
args = {
37
41
'input' : GraphQLArgument (GraphQLNonNull (R [Input ]))
38
42
},
39
- resolver = lambda obj , args , info : resolver ( obj , Input ( args . get ( 'input' )), info )
43
+ resolver = functools . partial ( mcs . _process_resolver , resolver , Input )
40
44
)))
41
45
42
46
@staticmethod
@@ -46,3 +50,15 @@ def _register(mutation_name, mutation):
46
50
@staticmethod
47
51
def _get_registry ():
48
52
raise NotImplementedError ('_get_registry must be implemented in the sub-metaclass' )
53
+
54
+ @staticmethod
55
+ def _process_input_attrs (registry , input_attrs ):
56
+ return input_attrs
57
+
58
+ @staticmethod
59
+ def _process_output_attrs (registry , output_attrs ):
60
+ return output_attrs
61
+
62
+ @staticmethod
63
+ def _process_resolver (resolver , input_class , obj , args , info ):
64
+ return resolver (obj , input_class (args .get ('input' )), info )
0 commit comments