2020from aiohttp .client_reqrep import Fingerprint
2121from aiohttp .helpers import BasicAuth
2222from aiohttp .typedefs import LooseCookies , LooseHeaders
23- from graphql import DocumentNode , ExecutionResult , print_ast
23+ from graphql import ExecutionResult
2424from multidict import CIMultiDictProxy
2525
2626from ..graphql_request import GraphQLRequest
@@ -164,25 +164,13 @@ async def close(self) -> None:
164164
165165 self .session = None
166166
167- def _build_payload (self , req : GraphQLRequest ) -> Dict [str , Any ]:
168- query_str = print_ast (req .document )
169- payload : Dict [str , Any ] = {"query" : query_str }
170-
171- if req .operation_name :
172- payload ["operationName" ] = req .operation_name
173-
174- if req .variable_values :
175- payload ["variables" ] = req .variable_values
176-
177- return payload
178-
179167 def _prepare_batch_request (
180168 self ,
181169 reqs : List [GraphQLRequest ],
182170 extra_args : Optional [Dict [str , Any ]] = None ,
183171 ) -> Dict [str , Any ]:
184172
185- payload = [self . _build_payload ( req ) for req in reqs ]
173+ payload = [req . payload for req in reqs ]
186174
187175 post_args = {"json" : payload }
188176
@@ -198,15 +186,15 @@ def _prepare_batch_request(
198186
199187 def _prepare_request (
200188 self ,
201- req : GraphQLRequest ,
189+ request : GraphQLRequest ,
202190 extra_args : Optional [Dict [str , Any ]] = None ,
203191 upload_files : bool = False ,
204192 ) -> Dict [str , Any ]:
205193
206- payload = self . _build_payload ( req )
194+ payload = request . payload
207195
208196 if upload_files :
209- post_args = self ._prepare_file_uploads (req , payload )
197+ post_args = self ._prepare_file_uploads (request , payload )
210198 else :
211199 post_args = {"json" : payload }
212200
@@ -228,11 +216,11 @@ def _prepare_request(
228216 return post_args
229217
230218 def _prepare_file_uploads (
231- self , req : GraphQLRequest , payload : Dict [str , Any ]
219+ self , request : GraphQLRequest , payload : Dict [str , Any ]
232220 ) -> Dict [str , Any ]:
233221
234222 # If the upload_files flag is set, then we need variable_values
235- variable_values = req .variable_values
223+ variable_values = request .variable_values
236224 assert variable_values is not None
237225
238226 # If we upload files, we will extract the files present in the
@@ -359,36 +347,28 @@ def _raise_invalid_result(self, result_text: str, reason: str) -> None:
359347
360348 async def execute (
361349 self ,
362- document : DocumentNode ,
363- variable_values : Optional [Dict [str , Any ]] = None ,
364- operation_name : Optional [str ] = None ,
350+ request : GraphQLRequest ,
351+ * ,
365352 extra_args : Optional [Dict [str , Any ]] = None ,
366353 upload_files : bool = False ,
367354 ) -> ExecutionResult :
368- """Execute the provided document AST against the configured remote server
355+ """Execute the provided request against the configured remote server
369356 using the current session.
370357 This uses the aiohttp library to perform a HTTP POST request asynchronously
371358 to the remote server.
372359
373360 Don't call this coroutine directly on the transport, instead use
374361 :code:`execute` on a client or a session.
375362
376- :param document: the parsed GraphQL request
377- :param variable_values: An optional Dict of variable values
378- :param operation_name: An optional Operation name for the request
363+ :param request: GraphQL request as a
364+ :class:`GraphQLRequest <gql.GraphQLRequest>` object.
379365 :param extra_args: additional arguments to send to the aiohttp post method
380366 :param upload_files: Set to True if you want to put files in the variable values
381367 :returns: an ExecutionResult object.
382368 """
383369
384- req = GraphQLRequest (
385- document = document ,
386- variable_values = variable_values ,
387- operation_name = operation_name ,
388- )
389-
390370 post_args = self ._prepare_request (
391- req ,
371+ request ,
392372 extra_args ,
393373 upload_files ,
394374 )
@@ -434,9 +414,7 @@ async def execute_batch(
434414
435415 def subscribe (
436416 self ,
437- document : DocumentNode ,
438- variable_values : Optional [Dict [str , Any ]] = None ,
439- operation_name : Optional [str ] = None ,
417+ request : GraphQLRequest ,
440418 ) -> AsyncGenerator [ExecutionResult , None ]:
441419 """Subscribe is not supported on HTTP.
442420
0 commit comments