11from inspect import iscoroutinefunction
2- from typing import Any , Callable
2+ from typing import Any , Callable , Dict , Optional
33
4- from graphql .error import GraphQLError
5- from graphql .pyutils import AwaitableOrValue , inspect
6- from graphql .type import (
4+ from graphql import (
5+ GraphQLError ,
76 GraphQLArgument ,
87 GraphQLField ,
98 GraphQLFieldMap ,
1615 GraphQLString ,
1716 Thunk ,
1817)
19-
18+ from graphql . pyutils import AwaitableOrValue , inspect
2019
2120# Note: Contrary to the Javascript implementation of MutationFn,
2221# 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:
3231
3332
3433class NullResult :
35- def __init__ (self , clientMutationId = None ):
34+ def __init__ (self , clientMutationId : Optional [ str ] = None ) -> None :
3635 self .clientMutationId = clientMutationId
3736
3837
@@ -41,8 +40,9 @@ def mutation_with_client_mutation_id(
4140 input_fields : Thunk [GraphQLInputFieldMap ],
4241 output_fields : Thunk [GraphQLFieldMap ],
4342 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 ,
4646) -> GraphQLField :
4747 """
4848 Returns a GraphQLFieldConfig for the specified mutation.
@@ -78,7 +78,7 @@ def augmented_output_fields() -> GraphQLFieldMap:
7878 if iscoroutinefunction (mutate_and_get_payload ):
7979
8080 # noinspection PyShadowingBuiltins
81- async def resolve (_root , info , input ) :
81+ async def resolve (_root : Any , info : GraphQLResolveInfo , input : Dict ) -> Any :
8282 payload = await mutate_and_get_payload (info , ** input )
8383 try :
8484 clientMutationId = input ["clientMutationId" ]
@@ -95,7 +95,10 @@ async def resolve(_root, info, input):
9595
9696 else :
9797
98- def resolve (_root , info , input ):
98+ # noinspection PyShadowingBuiltins
99+ def resolve ( # type: ignore
100+ _root : Any , info : GraphQLResolveInfo , input : Dict
101+ ) -> Any :
99102 payload = mutate_and_get_payload (info , ** input )
100103 try :
101104 clientMutationId = input ["clientMutationId" ]
@@ -107,7 +110,7 @@ def resolve(_root, info, input):
107110 if payload is None :
108111 payload = NullResult (clientMutationId )
109112 else :
110- payload .clientMutationId = clientMutationId
113+ payload .clientMutationId = clientMutationId # type: ignore
111114 return payload
112115
113116 return GraphQLField (
@@ -116,4 +119,5 @@ def resolve(_root, info, input):
116119 deprecation_reason = deprecation_reason ,
117120 args = {"input" : GraphQLArgument (GraphQLNonNull (input_type ))},
118121 resolve = resolve ,
122+ extensions = extensions ,
119123 )
0 commit comments