@@ -59,15 +59,22 @@ def __init__(
59
59
60
60
def _prepare_request (
61
61
self ,
62
- req : GraphQLRequest ,
62
+ request : Union [GraphQLRequest , List [GraphQLRequest ]],
63
+ * ,
63
64
extra_args : Optional [Dict [str , Any ]] = None ,
64
65
upload_files : bool = False ,
65
66
) -> Dict [str , Any ]:
66
67
67
- payload = req .payload
68
+ payload : Dict | List
69
+ if isinstance (request , GraphQLRequest ):
70
+ payload = request .payload
71
+ else :
72
+ payload = [req .payload for req in request ]
68
73
69
74
if upload_files :
70
- post_args = self ._prepare_file_uploads (req , payload )
75
+ assert isinstance (payload , Dict )
76
+ assert isinstance (request , GraphQLRequest )
77
+ post_args = self ._prepare_file_uploads (request , payload )
71
78
else :
72
79
post_args = {"json" : payload }
73
80
@@ -81,26 +88,6 @@ def _prepare_request(
81
88
82
89
return post_args
83
90
84
- def _prepare_batch_request (
85
- self ,
86
- reqs : List [GraphQLRequest ],
87
- extra_args : Optional [Dict [str , Any ]] = None ,
88
- ) -> Dict [str , Any ]:
89
-
90
- payload = [req .payload for req in reqs ]
91
-
92
- post_args = {"json" : payload }
93
-
94
- # Log the payload
95
- if log .isEnabledFor (logging .DEBUG ):
96
- log .debug (">>> %s" , self .json_serialize (payload ))
97
-
98
- # Pass post_args to aiohttp post method
99
- if extra_args :
100
- post_args .update (extra_args )
101
-
102
- return post_args
103
-
104
91
def _prepare_file_uploads (
105
92
self ,
106
93
request : GraphQLRequest ,
@@ -244,7 +231,7 @@ def connect(self):
244
231
245
232
self .client = httpx .Client (** self .kwargs )
246
233
247
- def execute ( # type: ignore
234
+ def execute (
248
235
self ,
249
236
request : GraphQLRequest ,
250
237
* ,
@@ -269,8 +256,8 @@ def execute( # type: ignore
269
256
270
257
post_args = self ._prepare_request (
271
258
request ,
272
- extra_args ,
273
- upload_files ,
259
+ extra_args = extra_args ,
260
+ upload_files = upload_files ,
274
261
)
275
262
276
263
try :
@@ -292,7 +279,7 @@ def execute_batch(
292
279
:code:`execute_batch` on a client or a session.
293
280
294
281
:param reqs: GraphQL requests as a list of GraphQLRequest objects.
295
- :param extra_args: additional arguments to send to the aiohttp post method
282
+ :param extra_args: additional arguments to send to the httpx post method
296
283
:return: A list of results of execution.
297
284
For every result `data` is the result of executing the query,
298
285
`errors` is null if no errors occurred, and is a non-empty array
@@ -302,9 +289,9 @@ def execute_batch(
302
289
if not self .client :
303
290
raise TransportClosed ("Transport is not connected" )
304
291
305
- post_args = self ._prepare_batch_request (
292
+ post_args = self ._prepare_request (
306
293
reqs ,
307
- extra_args ,
294
+ extra_args = extra_args ,
308
295
)
309
296
310
297
response = self .client .post (self .url , ** post_args )
@@ -361,8 +348,8 @@ async def execute(
361
348
362
349
post_args = self ._prepare_request (
363
350
request ,
364
- extra_args ,
365
- upload_files ,
351
+ extra_args = extra_args ,
352
+ upload_files = upload_files ,
366
353
)
367
354
368
355
try :
@@ -384,7 +371,7 @@ async def execute_batch(
384
371
:code:`execute_batch` on a client or a session.
385
372
386
373
:param reqs: GraphQL requests as a list of GraphQLRequest objects.
387
- :param extra_args: additional arguments to send to the aiohttp post method
374
+ :param extra_args: additional arguments to send to the httpx post method
388
375
:return: A list of results of execution.
389
376
For every result `data` is the result of executing the query,
390
377
`errors` is null if no errors occurred, and is a non-empty array
@@ -394,9 +381,9 @@ async def execute_batch(
394
381
if not self .client :
395
382
raise TransportClosed ("Transport is not connected" )
396
383
397
- post_args = self ._prepare_batch_request (
384
+ post_args = self ._prepare_request (
398
385
reqs ,
399
- extra_args ,
386
+ extra_args = extra_args ,
400
387
)
401
388
402
389
response = await self .client .post (self .url , ** post_args )
0 commit comments