1
1
from inspect import iscoroutinefunction
2
- from typing import Any , Callable
2
+ from typing import Any , Callable , Dict , Optional
3
3
4
- from graphql .error import GraphQLError
5
- from graphql .pyutils import AwaitableOrValue , inspect
6
- from graphql .type import (
4
+ from graphql import (
5
+ GraphQLError ,
7
6
GraphQLArgument ,
8
7
GraphQLField ,
9
8
GraphQLFieldMap ,
16
15
GraphQLString ,
17
16
Thunk ,
18
17
)
19
-
18
+ from graphql . pyutils import AwaitableOrValue , inspect
20
19
21
20
# Note: Contrary to the Javascript implementation of MutationFn,
22
21
# the context is passed as part of the GraphQLResolveInfo and any arguments
@@ -32,7 +31,7 @@ def resolve_maybe_thunk(thing_or_thunk: Thunk) -> Any:
32
31
33
32
34
33
class NullResult :
35
- def __init__ (self , clientMutationId = None ):
34
+ def __init__ (self , clientMutationId : Optional [ str ] = None ) -> None :
36
35
self .clientMutationId = clientMutationId
37
36
38
37
@@ -41,8 +40,9 @@ def mutation_with_client_mutation_id(
41
40
input_fields : Thunk [GraphQLInputFieldMap ],
42
41
output_fields : Thunk [GraphQLFieldMap ],
43
42
mutate_and_get_payload : MutationFn ,
44
- description : str = None ,
45
- deprecation_reason : str = None ,
43
+ description : Optional [str ] = None ,
44
+ deprecation_reason : Optional [str ] = None ,
45
+ extensions : Optional [Dict [str , Any ]] = None ,
46
46
) -> GraphQLField :
47
47
"""
48
48
Returns a GraphQLFieldConfig for the specified mutation.
@@ -78,7 +78,7 @@ def augmented_output_fields() -> GraphQLFieldMap:
78
78
if iscoroutinefunction (mutate_and_get_payload ):
79
79
80
80
# noinspection PyShadowingBuiltins
81
- async def resolve (_root , info , input ) :
81
+ async def resolve (_root : Any , info : GraphQLResolveInfo , input : Dict ) -> Any :
82
82
payload = await mutate_and_get_payload (info , ** input )
83
83
try :
84
84
clientMutationId = input ["clientMutationId" ]
@@ -95,7 +95,10 @@ async def resolve(_root, info, input):
95
95
96
96
else :
97
97
98
- def resolve (_root , info , input ):
98
+ # noinspection PyShadowingBuiltins
99
+ def resolve ( # type: ignore
100
+ _root : Any , info : GraphQLResolveInfo , input : Dict
101
+ ) -> Any :
99
102
payload = mutate_and_get_payload (info , ** input )
100
103
try :
101
104
clientMutationId = input ["clientMutationId" ]
@@ -107,7 +110,7 @@ def resolve(_root, info, input):
107
110
if payload is None :
108
111
payload = NullResult (clientMutationId )
109
112
else :
110
- payload .clientMutationId = clientMutationId
113
+ payload .clientMutationId = clientMutationId # type: ignore
111
114
return payload
112
115
113
116
return GraphQLField (
@@ -116,4 +119,5 @@ def resolve(_root, info, input):
116
119
deprecation_reason = deprecation_reason ,
117
120
args = {"input" : GraphQLArgument (GraphQLNonNull (input_type ))},
118
121
resolve = resolve ,
122
+ extensions = extensions ,
119
123
)
0 commit comments