gql.transport.aiohttp¶
-
class
gql.transport.aiohttp.
AIOHTTPTransport
(url: str, headers: Optional[Union[Mapping[Union[str, multidict._multidict.istr], str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy]] = None, cookies: Optional[Union[Mapping[str, Union[str, BaseCookie[str], Morsel[Any]]], Iterable[Tuple[str, Union[str, BaseCookie[str], Morsel[Any]]]], BaseCookie[str]]] = None, auth: Optional[Union[aiohttp.helpers.BasicAuth, AppSyncAuthentication]] = None, ssl: Union[ssl.SSLContext, bool, aiohttp.client_reqrep.Fingerprint] = False, timeout: Optional[int] = None, ssl_close_timeout: Optional[Union[int, float]] = 10, client_session_args: Optional[Dict[str, Any]] = None)¶ Bases:
gql.transport.async_transport.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: Optional[Union[Mapping[Union[str, multidict._multidict.istr], str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy]] = None, cookies: Optional[Union[Mapping[str, Union[str, BaseCookie[str], Morsel[Any]]], Iterable[Tuple[str, Union[str, BaseCookie[str], Morsel[Any]]]], BaseCookie[str]]] = None, auth: Optional[Union[aiohttp.helpers.BasicAuth, AppSyncAuthentication]] = None, ssl: Union[ssl.SSLContext, bool, aiohttp.client_reqrep.Fingerprint] = False, timeout: Optional[int] = None, ssl_close_timeout: Optional[Union[int, float]] = 10, client_session_args: Optional[Dict[str, 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
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) → asyncio.locks.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: graphql.language.ast.DocumentNode, variable_values: Optional[Dict[str, Any]] = None, operation_name: Optional[str] = None, extra_args: Optional[Dict[str, Any]] = None, upload_files: bool = False) → graphql.execution.execute.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.
-