gql.transport.aiohttp

class gql.transport.aiohttp.AIOHTTPTransport(url: str, headers: ~typing.Optional[~typing.Union[~typing.Mapping[~typing.Union[str, ~multidict._multidict.istr], str], ~multidict._multidict.CIMultiDict, ~multidict._multidict.CIMultiDictProxy]] = None, cookies: ~typing.Optional[~typing.Union[~typing.Mapping[str, ~typing.Union[str, BaseCookie[str], Morsel[Any]]], ~typing.Iterable[~typing.Tuple[str, ~typing.Union[str, BaseCookie[str], Morsel[Any]]]], BaseCookie[str]]] = None, auth: ~typing.Optional[~typing.Union[~aiohttp.helpers.BasicAuth, AppSyncAuthentication]] = None, ssl: ~typing.Union[~ssl.SSLContext, bool, ~aiohttp.client_reqrep.Fingerprint] = False, timeout: ~typing.Optional[int] = None, ssl_close_timeout: ~typing.Optional[~typing.Union[int, float]] = 10, json_serialize: ~typing.Callable = <function dumps>, client_session_args: ~typing.Optional[~typing.Dict[str, ~typing.Any]] = 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.Optional[~typing.Union[~typing.Mapping[~typing.Union[str, ~multidict._multidict.istr], str], ~multidict._multidict.CIMultiDict, ~multidict._multidict.CIMultiDictProxy]] = None, cookies: ~typing.Optional[~typing.Union[~typing.Mapping[str, ~typing.Union[str, BaseCookie[str], Morsel[Any]]], ~typing.Iterable[~typing.Tuple[str, ~typing.Union[str, BaseCookie[str], Morsel[Any]]]], BaseCookie[str]]] = None, auth: ~typing.Optional[~typing.Union[~aiohttp.helpers.BasicAuth, AppSyncAuthentication]] = None, ssl: ~typing.Union[~ssl.SSLContext, bool, ~aiohttp.client_reqrep.Fingerprint] = False, timeout: ~typing.Optional[int] = None, ssl_close_timeout: ~typing.Optional[~typing.Union[int, float]] = 10, json_serialize: ~typing.Callable = <function dumps>, client_session_args: ~typing.Optional[~typing.Dict[str, ~typing.Any]] = 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 disable encryption

  • 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

  • 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.

static create_aiohttp_closed_event(session) Event

Work around aiohttp issue that doesn’t properly close transports on exit.

See https://github.com/aio-libs/aiohttp/issues/1925#issuecomment-639080209

Returns:

An event that will be set once all transports have been properly closed.

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(document: DocumentNode, variable_values: Optional[Dict[str, Any]] = None, operation_name: Optional[str] = None, extra_args: Optional[Dict[str, Any]] = None, upload_files: bool = False) ExecutionResult

Execute the provided document AST 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
  • document – the parsed GraphQL request

  • variable_values – An optional Dict of variable values

  • operation_name – An optional Operation name for the request

  • 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.