@@ -59,15 +59,22 @@ def __init__(
5959
6060 def _prepare_request (
6161 self ,
62- req : GraphQLRequest ,
62+ request : Union [GraphQLRequest , List [GraphQLRequest ]],
63+ * ,
6364 extra_args : Optional [Dict [str , Any ]] = None ,
6465 upload_files : bool = False ,
6566 ) -> Dict [str , Any ]:
6667
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 ]
6873
6974 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 )
7178 else :
7279 post_args = {"json" : payload }
7380
@@ -81,26 +88,6 @@ def _prepare_request(
8188
8289 return post_args
8390
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-
10491 def _prepare_file_uploads (
10592 self ,
10693 request : GraphQLRequest ,
@@ -244,7 +231,7 @@ def connect(self):
244231
245232 self .client = httpx .Client (** self .kwargs )
246233
247- def execute ( # type: ignore
234+ def execute (
248235 self ,
249236 request : GraphQLRequest ,
250237 * ,
@@ -269,8 +256,8 @@ def execute( # type: ignore
269256
270257 post_args = self ._prepare_request (
271258 request ,
272- extra_args ,
273- upload_files ,
259+ extra_args = extra_args ,
260+ upload_files = upload_files ,
274261 )
275262
276263 try :
@@ -292,7 +279,7 @@ def execute_batch(
292279 :code:`execute_batch` on a client or a session.
293280
294281 :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
296283 :return: A list of results of execution.
297284 For every result `data` is the result of executing the query,
298285 `errors` is null if no errors occurred, and is a non-empty array
@@ -302,9 +289,9 @@ def execute_batch(
302289 if not self .client :
303290 raise TransportClosed ("Transport is not connected" )
304291
305- post_args = self ._prepare_batch_request (
292+ post_args = self ._prepare_request (
306293 reqs ,
307- extra_args ,
294+ extra_args = extra_args ,
308295 )
309296
310297 response = self .client .post (self .url , ** post_args )
@@ -361,8 +348,8 @@ async def execute(
361348
362349 post_args = self ._prepare_request (
363350 request ,
364- extra_args ,
365- upload_files ,
351+ extra_args = extra_args ,
352+ upload_files = upload_files ,
366353 )
367354
368355 try :
@@ -384,7 +371,7 @@ async def execute_batch(
384371 :code:`execute_batch` on a client or a session.
385372
386373 :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
388375 :return: A list of results of execution.
389376 For every result `data` is the result of executing the query,
390377 `errors` is null if no errors occurred, and is a non-empty array
@@ -394,9 +381,9 @@ async def execute_batch(
394381 if not self .client :
395382 raise TransportClosed ("Transport is not connected" )
396383
397- post_args = self ._prepare_batch_request (
384+ post_args = self ._prepare_request (
398385 reqs ,
399- extra_args ,
386+ extra_args = extra_args ,
400387 )
401388
402389 response = await self .client .post (self .url , ** post_args )
0 commit comments