Transport

GraphQLTransport

class aiographql.client.transport.base.GraphQLTransport(*args, **kwargs)

Protocol for GraphQL transports.

async request(method: str, request: GraphQLRequest, serializer: GraphQLSerializer, **kwargs: Any) GraphQLResponse

Execute a GraphQL request.

Parameters:
Return type:

GraphQLResponse

async close() None

Close the transport and any underlying resources.

Return type:

None

AiohttpTransport

class aiographql.client.transport.aiohttp.AiohttpTransport(endpoint: str, session: aiohttp.ClientSession | None = None) None

Aiohttp implementation of GraphQLTransport.

Parameters:
async request(method: str, request: GraphQLRequest, serializer: GraphQLSerializer, **kwargs: Any) GraphQLResponse

Execute a GraphQL request using aiohttp.

Parameters:
Return type:

GraphQLResponse

async close() None

Close the transport and any underlying resources.

Return type:

None

HttpxTransport

class aiographql.client.transport.httpx.HttpxTransport(endpoint: str, client: httpx.AsyncClient | None = None, session: httpx.AsyncClient | None = None) None

Httpx implementation of GraphQLTransport.

Parameters:
  • endpoint (str)

  • client (AsyncClient | None)

  • session (AsyncClient | None)

async request(method: str, request: GraphQLRequest, serializer: GraphQLSerializer, **kwargs: Any) GraphQLResponse

Execute a GraphQL request using httpx.

Parameters:
Return type:

GraphQLResponse

async close() None

Close the transport and any underlying resources.

Return type:

None

AiohttpSubscriptionTransport

class aiographql.client.transport.aiohttp.AiohttpSubscriptionTransport(endpoint: str, session: ClientSession | None = None) None

Aiohttp implementation of GraphQLSubscriptionTransport.

Parameters:
async subscribe(endpoint: str, request: GraphQLRequest, serializer: GraphQLSerializer, **kwargs: Any) GraphQLWebSocketResponse

Execute a GraphQL subscription using aiohttp websockets.

Parameters:
Return type:

GraphQLWebSocketResponse

async close() None

Close the transport and any underlying resources.

Return type:

None

WebsocketSubscriptionTransport

class aiographql.client.transport.websocket.WebsocketSubscriptionTransport(endpoint: str) None

Websockets implementation of GraphQLSubscriptionTransport.

Parameters:

endpoint (str)

async subscribe(endpoint: str, request: GraphQLRequest, serializer: GraphQLSerializer, **kwargs: Any) GraphQLWebSocketResponse

Execute a GraphQL subscription using websockets.

Parameters:
Return type:

GraphQLWebSocketResponse

async close() None

Close the transport and any underlying resources.

Return type:

None

GraphQLWebSocketResponse

class aiographql.client.transport.base.GraphQLWebSocketResponse(*args, **kwargs)

Protocol for GraphQL WebSocket responses.

get_default_transport

aiographql.client.transport.get_default_transport(endpoint: str, transport: GraphQLTransport | None = None, session: GraphQLSession | None = None, client: GraphQLSession | None = None, **kwargs: Any) GraphQLTransport

Resolve the transport to use for making GraphQL requests.

Parameters:
  • endpoint (str) – The GraphQL endpoint URL.

  • transport (GraphQLTransport | None) – The transport to use. If not provided, the best available transport is automatically selected (preferring aiohttp). Must be a GraphQLTransport instance.

  • session (Union[ClientSession, AsyncClient, None]) – An optional GraphQLSession.

  • client (Union[ClientSession, AsyncClient, None]) – An optional httpx.AsyncClient.

  • kwargs (Any) – Additional arguments to pass to the transport constructor.

Return type:

GraphQLTransport

Returns:

A GraphQLTransport instance.

Raises:
  • ImportError – If the requested transport is not available.

  • RuntimeError – If “auto” transport is requested but no suitable transport is available.

get_default_subscription_transport

aiographql.client.transport.get_default_subscription_transport(endpoint: str, transport: GraphQLSubscriptionTransport | None = None, session: ClientSession | AsyncClient | None = None, **kwargs: Any) GraphQLSubscriptionTransport

Resolve the transport to use for making GraphQL subscriptions.

Parameters:
  • endpoint (str) – The GraphQL endpoint URL.

  • transport (GraphQLSubscriptionTransport | None) – The transport to use. If not provided, the best available transport is automatically selected. Must be a GraphQLSubscriptionTransport instance.

  • session (Union[ClientSession, AsyncClient, None]) – An optional GraphQLSession.

  • kwargs (Any) – Additional arguments to pass to the transport constructor.

Return type:

GraphQLSubscriptionTransport

Returns:

A GraphQLSubscriptionTransport instance.

Raises:
  • ImportError – If the requested transport is not available.

  • RuntimeError – If “auto” transport is requested but no suitable transport is available.