33from graphql import graphql , graphql_sync
44from graphql .type import (
55 GraphQLField ,
6+ GraphQLFieldMap ,
67 GraphQLInputField ,
78 GraphQLInt ,
89 GraphQLObjectType ,
@@ -20,85 +21,31 @@ def __init__(self, result, clientMutationId=None):
2021 self .result = result
2122
2223
23- def dummy_resolve (_info , ** _input ):
24- return Result (1 )
24+ def dummy_resolve (_info , inputData = None , clientMutationId = None ):
25+ return Result (inputData or 1 , clientMutationId )
2526
2627
27- simple_mutation = mutation_with_client_mutation_id (
28- "SimpleMutation" ,
29- input_fields = {},
30- output_fields = {"result" : GraphQLField (GraphQLInt )},
31- mutate_and_get_payload = dummy_resolve ,
32- )
33-
34- simple_mutation_with_description = mutation_with_client_mutation_id (
35- "SimpleMutationWithDescription" ,
36- description = "Simple Mutation Description" ,
37- input_fields = {},
38- output_fields = {"result" : GraphQLField (GraphQLInt )},
39- mutate_and_get_payload = dummy_resolve ,
40- )
41-
42- simple_mutation_with_deprecation_reason = mutation_with_client_mutation_id (
43- "SimpleMutationWithDeprecationReason" ,
44- input_fields = {},
45- output_fields = {"result" : GraphQLField (GraphQLInt )},
46- mutate_and_get_payload = dummy_resolve ,
47- deprecation_reason = "Just because" ,
48- )
49-
50- # noinspection PyPep8Naming
51- simple_mutation_with_thunk_fields = mutation_with_client_mutation_id (
52- "SimpleMutationWithThunkFields" ,
53- input_fields = lambda : {"inputData" : GraphQLInputField (GraphQLInt )},
54- output_fields = lambda : {"result" : GraphQLField (GraphQLInt )},
55- mutate_and_get_payload = lambda _info , inputData , ** _input : Result (inputData ),
56- )
57-
58-
59- # noinspection PyPep8Naming
60- async def mutate_and_get_one_as_payload_async (_info , ** _input ):
61- return Result (1 )
62-
63-
64- simple_async_mutation = mutation_with_client_mutation_id (
65- "SimpleAsyncMutation" ,
66- input_fields = {},
67- output_fields = {"result" : GraphQLField (GraphQLInt )},
68- mutate_and_get_payload = mutate_and_get_one_as_payload_async ,
69- )
70-
71- simple_root_value_mutation = mutation_with_client_mutation_id (
72- "SimpleRootValueMutation" ,
73- input_fields = {},
74- output_fields = {"result" : GraphQLField (GraphQLInt )},
75- mutate_and_get_payload = lambda info , ** _input : info .root_value ,
76- )
77-
78- query_type : GraphQLObjectType = GraphQLObjectType (
79- "Query" , lambda : {"query" : GraphQLField (query_type )}
80- )
28+ async def dummy_resolve_async (_info , inputData = None , clientMutationId = None ):
29+ return Result (inputData or 1 , clientMutationId )
8130
82- mutation_type = GraphQLObjectType (
83- "Mutation" ,
84- fields = {
85- "simpleMutation" : simple_mutation ,
86- "simpleMutationWithDescription" : simple_mutation_with_description ,
87- "simpleMutationWithDeprecationReason" : simple_mutation_with_deprecation_reason ,
88- "simpleMutationWithThunkFields" : simple_mutation_with_thunk_fields ,
89- "simpleAsyncMutation" : simple_async_mutation ,
90- "simpleRootValueMutation" : simple_root_value_mutation ,
91- },
92- )
9331
94- schema = GraphQLSchema (query = query_type , mutation = mutation_type )
32+ def wrap_in_schema (mutation_fields : GraphQLFieldMap ) -> GraphQLSchema :
33+ query_type = GraphQLObjectType (
34+ "DummyQuery" , fields = {"dummy" : GraphQLField (GraphQLInt )}
35+ )
36+ mutation_type = GraphQLObjectType ("Mutation" , fields = mutation_fields )
37+ return GraphQLSchema (query_type , mutation_type )
9538
9639
9740def describe_mutation_with_client_mutation_id ():
9841 def requires_an_argument ():
42+ some_mutation = mutation_with_client_mutation_id (
43+ "SomeMutation" , {}, {"result" : GraphQLField (GraphQLInt )}, dummy_resolve
44+ )
45+ schema = wrap_in_schema ({"someMutation" : some_mutation })
9946 source = """
10047 mutation {
101- simpleMutation {
48+ someMutation {
10249 result
10350 }
10451 }
@@ -107,41 +54,51 @@ def requires_an_argument():
10754 None ,
10855 [
10956 {
110- "message" : "Field 'simpleMutation ' argument 'input'"
111- " of type 'SimpleMutationInput !' is required,"
57+ "message" : "Field 'someMutation ' argument 'input'"
58+ " of type 'SomeMutationInput !' is required,"
11259 " but it was not provided." ,
11360 "locations" : [(3 , 15 )],
11461 }
11562 ],
11663 )
11764
11865 def returns_the_same_client_mutation_id ():
66+ some_mutation = mutation_with_client_mutation_id (
67+ "SomeMutation" , {}, {"result" : GraphQLField (GraphQLInt )}, dummy_resolve
68+ )
69+ schema = wrap_in_schema ({"someMutation" : some_mutation })
11970 source = """
12071 mutation {
121- simpleMutation (input: {clientMutationId: "abc"}) {
72+ someMutation (input: {clientMutationId: "abc"}) {
12273 result
12374 clientMutationId
12475 }
12576 }
12677 """
12778 assert graphql_sync (schema , source ) == (
128- {"simpleMutation " : {"result" : 1 , "clientMutationId" : "abc" }},
79+ {"someMutation " : {"result" : 1 , "clientMutationId" : "abc" }},
12980 None ,
13081 )
13182
13283 def supports_thunks_as_input_and_output_fields ():
84+ some_mutation = mutation_with_client_mutation_id (
85+ "SomeMutation" ,
86+ {"inputData" : GraphQLInputField (GraphQLInt )},
87+ {"result" : GraphQLField (GraphQLInt )},
88+ dummy_resolve ,
89+ )
90+ schema = wrap_in_schema ({"someMutation" : some_mutation })
13391 source = """
13492 mutation {
135- simpleMutationWithThunkFields(
136- input: {inputData: 1234, clientMutationId: "abc"}) {
93+ someMutation(input: {inputData: 1234, clientMutationId: "abc"}) {
13794 result
13895 clientMutationId
13996 }
14097 }
14198 """
14299 assert graphql_sync (schema , source ) == (
143100 {
144- "simpleMutationWithThunkFields " : {
101+ "someMutation " : {
145102 "result" : 1234 ,
146103 "clientMutationId" : "abc" ,
147104 }
@@ -151,48 +108,102 @@ def supports_thunks_as_input_and_output_fields():
151108
152109 @mark .asyncio
153110 async def supports_async_mutations ():
111+ some_mutation = mutation_with_client_mutation_id (
112+ "SomeMutation" ,
113+ {},
114+ {"result" : GraphQLField (GraphQLInt )},
115+ dummy_resolve_async ,
116+ )
117+ schema = wrap_in_schema ({"someMutation" : some_mutation })
154118 source = """
155119 mutation {
156- simpleAsyncMutation (input: {clientMutationId: "abc"}) {
120+ someMutation (input: {clientMutationId: "abc"}) {
157121 result
158122 clientMutationId
159123 }
160124 }
161125 """
162126 assert await graphql (schema , source ) == (
163- {"simpleAsyncMutation " : {"result" : 1 , "clientMutationId" : "abc" }},
127+ {"someMutation " : {"result" : 1 , "clientMutationId" : "abc" }},
164128 None ,
165129 )
166130
167131 def can_access_root_value ():
132+ some_mutation = mutation_with_client_mutation_id (
133+ "SomeMutation" ,
134+ {},
135+ {"result" : GraphQLField (GraphQLInt )},
136+ lambda info , clientMutationId = None : Result (
137+ info .root_value , clientMutationId
138+ ),
139+ )
140+ schema = wrap_in_schema ({"someMutation" : some_mutation })
168141 source = """
169142 mutation {
170- simpleRootValueMutation (input: {clientMutationId: "abc"}) {
143+ someMutation (input: {clientMutationId: "abc"}) {
171144 result
172145 clientMutationId
173146 }
174147 }
175148 """
176- assert graphql_sync (schema , source , root_value = Result ( 1 ) ) == (
177- {"simpleRootValueMutation " : {"result" : 1 , "clientMutationId" : "abc" }},
149+ assert graphql_sync (schema , source , root_value = 1 ) == (
150+ {"someMutation " : {"result" : 1 , "clientMutationId" : "abc" }},
178151 None ,
179152 )
180153
181154 def supports_mutations_returning_null ():
155+ some_mutation = mutation_with_client_mutation_id (
156+ "SomeMutation" ,
157+ {},
158+ {"result" : GraphQLField (GraphQLInt )},
159+ lambda _info , ** _input : None ,
160+ )
161+ schema = wrap_in_schema ({"someMutation" : some_mutation })
182162 source = """
183163 mutation {
184- simpleRootValueMutation (input: {clientMutationId: "abc"}) {
164+ someMutation (input: {clientMutationId: "abc"}) {
185165 result
186166 clientMutationId
187167 }
188168 }
189169 """
190- assert graphql_sync (schema , source , root_value = None ) == (
191- {"simpleRootValueMutation " : {"result" : None , "clientMutationId" : "abc" }},
170+ assert graphql_sync (schema , source ) == (
171+ {"someMutation " : {"result" : None , "clientMutationId" : "abc" }},
192172 None ,
193173 )
194174
195175 def describe_introspection ():
176+ simple_mutation = mutation_with_client_mutation_id (
177+ "SimpleMutation" ,
178+ input_fields = {},
179+ output_fields = {"result" : GraphQLField (GraphQLInt )},
180+ mutate_and_get_payload = dummy_resolve ,
181+ )
182+
183+ simple_mutation_with_description = mutation_with_client_mutation_id (
184+ "SimpleMutationWithDescription" ,
185+ description = "Simple Mutation Description" ,
186+ input_fields = {},
187+ output_fields = {"result" : GraphQLField (GraphQLInt )},
188+ mutate_and_get_payload = dummy_resolve ,
189+ )
190+
191+ simple_mutation_with_deprecation_reason = mutation_with_client_mutation_id (
192+ "SimpleMutationWithDeprecationReason" ,
193+ input_fields = {},
194+ output_fields = {"result" : GraphQLField (GraphQLInt )},
195+ mutate_and_get_payload = dummy_resolve ,
196+ deprecation_reason = "Just because" ,
197+ )
198+
199+ schema = wrap_in_schema (
200+ {
201+ "simpleMutation" : simple_mutation ,
202+ "simpleMutationWithDescription" : simple_mutation_with_description ,
203+ "simpleMutationWithDeprecationReason" : simple_mutation_with_deprecation_reason , # noqa: E501
204+ }
205+ )
206+
196207 def contains_correct_input ():
197208 source = """
198209 {
@@ -334,67 +345,6 @@ def contains_correct_field():
334345 "kind" : "OBJECT" ,
335346 },
336347 },
337- {
338- "name" : "simpleMutationWithThunkFields" ,
339- "args" : [
340- {
341- "name" : "input" ,
342- "type" : {
343- "name" : None ,
344- "kind" : "NON_NULL" ,
345- "ofType" : {
346- "name" : "SimpleMutation"
347- "WithThunkFieldsInput" ,
348- "kind" : "INPUT_OBJECT" ,
349- },
350- },
351- }
352- ],
353- "type" : {
354- "name" : "SimpleMutationWithThunkFieldsPayload" ,
355- "kind" : "OBJECT" ,
356- },
357- },
358- {
359- "name" : "simpleAsyncMutation" ,
360- "args" : [
361- {
362- "name" : "input" ,
363- "type" : {
364- "name" : None ,
365- "kind" : "NON_NULL" ,
366- "ofType" : {
367- "name" : "SimpleAsyncMutationInput" ,
368- "kind" : "INPUT_OBJECT" ,
369- },
370- },
371- }
372- ],
373- "type" : {
374- "name" : "SimpleAsyncMutationPayload" ,
375- "kind" : "OBJECT" ,
376- },
377- },
378- {
379- "name" : "simpleRootValueMutation" ,
380- "args" : [
381- {
382- "name" : "input" ,
383- "type" : {
384- "name" : None ,
385- "kind" : "NON_NULL" ,
386- "ofType" : {
387- "name" : "SimpleRootValueMutationInput" , # noqa: E501
388- "kind" : "INPUT_OBJECT" ,
389- },
390- },
391- }
392- ],
393- "type" : {
394- "name" : "SimpleRootValueMutationPayload" ,
395- "kind" : "OBJECT" ,
396- },
397- },
398348 ]
399349 }
400350 }
@@ -425,15 +375,6 @@ def contains_correct_descriptions():
425375 "name" : "simpleMutationWithDescription" ,
426376 "description" : "Simple Mutation Description" ,
427377 },
428- {
429- "name" : "simpleMutationWithThunkFields" ,
430- "description" : None ,
431- },
432- {"name" : "simpleAsyncMutation" , "description" : None },
433- {
434- "name" : "simpleRootValueMutation" ,
435- "description" : None ,
436- },
437378 ]
438379 }
439380 }
@@ -475,21 +416,6 @@ def contains_correct_deprecation_reason():
475416 "isDeprecated" : True ,
476417 "deprecationReason" : "Just because" ,
477418 },
478- {
479- "name" : "simpleMutationWithThunkFields" ,
480- "isDeprecated" : False ,
481- "deprecationReason" : None ,
482- },
483- {
484- "name" : "simpleAsyncMutation" ,
485- "isDeprecated" : False ,
486- "deprecationReason" : None ,
487- },
488- {
489- "name" : "simpleRootValueMutation" ,
490- "isDeprecated" : False ,
491- "deprecationReason" : None ,
492- },
493419 ]
494420 }
495421 }
0 commit comments