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 | str = 'ssl_warning', 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 | str = 'ssl_warning', 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 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
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.
- 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: Dict[str, Any] | None = None, operation_name: str | None = None, extra_args: Dict[str, Any] | None = 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.