5
5
6
6
from promise import Promise
7
7
8
- from ..types import AbstractType , Argument , Field , InputObjectType , String
9
- from ..types .objecttype import ObjectType , ObjectTypeMeta
8
+ from ..types import Field , AbstractType , Argument , InputObjectType , String
9
+ from ..types .mutation import Mutation , MutationMeta
10
+ from ..types .objecttype import ObjectTypeMeta
10
11
from ..utils .is_base_type import is_base_type
11
12
from ..utils .props import props
12
13
13
14
14
- class ClientIDMutationMeta (ObjectTypeMeta ):
15
-
15
+ class ClientIDMutationMeta (MutationMeta ):
16
16
def __new__ (cls , name , bases , attrs ):
17
17
# Also ensure initialization is only performed for subclasses of
18
18
# Mutation
@@ -23,13 +23,13 @@ def __new__(cls, name, bases, attrs):
23
23
base_name = re .sub ('Payload$' , '' , name )
24
24
if 'client_mutation_id' not in attrs :
25
25
attrs ['client_mutation_id' ] = String (name = 'clientMutationId' )
26
- cls = ObjectTypeMeta .__new__ (cls , '{}Payload' .format (base_name ), bases , attrs )
26
+ cls = ObjectTypeMeta .__new__ (cls , '{}Payload' .format (base_name ), bases ,
27
+ attrs )
27
28
mutate_and_get_payload = getattr (cls , 'mutate_and_get_payload' , None )
28
29
if cls .mutate and cls .mutate .__func__ == ClientIDMutation .mutate .__func__ :
29
30
assert mutate_and_get_payload , (
30
31
"{}.mutate_and_get_payload method is required"
31
- " in a ClientIDMutation."
32
- ).format (name )
32
+ " in a ClientIDMutation." ).format (name )
33
33
input_attrs = {}
34
34
bases = ()
35
35
if not input_class :
@@ -39,13 +39,18 @@ def __new__(cls, name, bases, attrs):
39
39
else :
40
40
bases += (input_class , )
41
41
input_attrs ['client_mutation_id' ] = String (name = 'clientMutationId' )
42
- cls .Input = type ('{}Input' .format (base_name ), bases + (InputObjectType ,), input_attrs )
43
- cls .Field = partial (Field , cls , resolver = cls .mutate , input = Argument (cls .Input , required = True ))
42
+ cls .Input = type ('{}Input' .format (base_name ),
43
+ bases + (InputObjectType , ), input_attrs )
44
+ output_class = getattr (cls , 'Output' , cls )
45
+ cls .Field = partial (
46
+ Field ,
47
+ output_class ,
48
+ resolver = cls .mutate ,
49
+ input = Argument (cls .Input , required = True ))
44
50
return cls
45
51
46
52
47
- class ClientIDMutation (six .with_metaclass (ClientIDMutationMeta , ObjectType )):
48
-
53
+ class ClientIDMutation (six .with_metaclass (ClientIDMutationMeta , Mutation )):
49
54
@classmethod
50
55
def mutate (cls , root , args , context , info ):
51
56
input = args .get ('input' )
@@ -54,11 +59,10 @@ def on_resolve(payload):
54
59
try :
55
60
payload .client_mutation_id = input .get ('clientMutationId' )
56
61
except :
57
- raise Exception ((
58
- 'Cannot set client_mutation_id in the payload object {}'
59
- ).format (repr (payload )))
62
+ raise Exception (
63
+ ( 'Cannot set client_mutation_id in the payload object {}'
64
+ ).format (repr (payload )))
60
65
return payload
61
66
62
67
return Promise .resolve (
63
- cls .mutate_and_get_payload (input , context , info )
64
- ).then (on_resolve )
68
+ cls .mutate_and_get_payload (input , context , info )).then (on_resolve )
0 commit comments