gql.transport.aiohttp

class gql.transport.aiohttp.AIOHTTPTransport(url: str, headers: ~typing.Mapping[str, str] | ~typing.Mapping[~multidict._multidict.istr, str] | ~multidict._multidict.CIMultiDict | ~multidict._multidict.CIMultiDictProxy | ~typing.Iterable[~typing.Tuple[str | ~multidict._multidict.istr, str]] | None = None, cookies: ~typing.Mapping[str, str | BaseCookie[str] | Morsel[Any]] | ~typing.Iterable[~typing.Tuple[str, str | BaseCookie[str] | Morsel[Any]]] | BaseCookie[str] | None = None, auth: ~aiohttp.helpers.BasicAuth | AppSyncAuthentication | None = None, ssl: ~ssl.SSLContext | bool | ~aiohttp.client_reqrep.Fingerprint = True, timeout: int | None = None, ssl_close_timeout: int | float | None = 10, json_serialize: ~typing.Callable = <function dumps>, json_deserialize: ~typing.Callable = <function loads>, client_session_args: ~typing.Dict[str, ~typing.Any] | None = None)

Bases: AsyncTransport

Async Transport to execute GraphQL queries on remote servers with an HTTP connection.

This transport use the aiohttp library with asyncio.

file_classes: Tuple[Type[Any], ...] = (<class 'io.IOBase'>, <class 'aiohttp.streams.StreamReader'>, typing.AsyncGenerator)
__init__(url: str, headers: ~typing.Mapping[str, str] | ~typing.Mapping[~multidict._multidict.istr, str] | ~multidict._multidict.CIMultiDict | ~multidict._multidict.CIMultiDictProxy | ~typing.Iterable[~typing.Tuple[str | ~multidict._multidict.istr, str]] | None = None, cookies: ~typing.Mapping[str, str | BaseCookie[str] | Morsel[Any]] | ~typing.Iterable[~typing.Tuple[str, str | BaseCookie[str] | Morsel[Any]]] | BaseCookie[str] | None = None, auth: ~aiohttp.helpers.BasicAuth | AppSyncAuthentication | None = None, ssl: ~ssl.SSLContext | bool | ~aiohttp.client_reqrep.Fingerprint = True, timeout: int | None = None, ssl_close_timeout: int | float | None = 10, json_serialize: ~typing.Callable = <function dumps>, json_deserialize: ~typing.Callable = <function loads>, client_session_args: ~typing.Dict[str, ~typing.Any] | None = None) None

Initialize the transport with the given aiohttp parameters.

Parameters:
  • url – The GraphQL server URL. Example: ‘https://server.com:PORT/path’.

  • headers – Dict of HTTP Headers.

  • cookies – Dict of HTTP cookies.

  • auth – BasicAuth object to enable Basic HTTP auth if needed Or Appsync Authentication class

  • ssl – ssl_context of the connection. Use ssl=False to not verify ssl certificates.

  • ssl_close_timeout – Timeout in seconds to wait for the ssl connection to close properly

  • json_serialize – Json serializer callable. By default json.dumps() function

  • json_deserialize – Json deserializer callable. By default json.loads() function

  • client_session_args – Dict of extra args passed to aiohttp.ClientSession

async connect() None

Coroutine which will create an aiohttp ClientSession() as self.session.

Don’t call this coroutine directly on the transport, instead use async with on the client and this coroutine will be executed to create the session.

Should be cleaned with a call to the close coroutine.

async close() None

Coroutine which will close the aiohttp session.

Don’t call this coroutine directly on the transport, instead use async with on the client and this coroutine will be executed when you exit the async context manager.

async execute(request: GraphQLRequest, *, extra_args: Dict[str, Any] | None = None, upload_files: bool = False) ExecutionResult

Execute the provided request against the configured remote server using the current session. This uses the aiohttp library to perform a HTTP POST request asynchronously to the remote server.

Don’t call this coroutine directly on the transport, instead use execute on a client or a session.

Parameters:
  • request – GraphQL request as a GraphQLRequest object.

  • extra_args – additional arguments to send to the aiohttp post method

  • upload_files – Set to True if you want to put files in the variable values

Returns:

an ExecutionResult object.

async execute_batch(reqs: List[GraphQLRequest], extra_args: Dict[str, Any] | None = None) List[ExecutionResult]

Execute multiple GraphQL requests in a batch.

Don’t call this coroutine directly on the transport, instead use execute_batch on a client or a session.

Parameters:
  • reqs – GraphQL requests as a list of GraphQLRequest objects.

  • extra_args – additional arguments to send to the aiohttp post method

Returns:

A list of results of execution. For every result data is the result of executing the query, errors is null if no errors occurred, and is a non-empty array if an error occurred.