gql.transport.common.adapters.websockets¶
- class gql.transport.common.adapters.websockets.WebSocketsAdapter(url: str, *, headers: Optional[Union[Headers, Mapping[str, str], Iterable[tuple[str, str]], SupportsKeysAndGetItem]] = None, ssl: Union[SSLContext, bool] = False, connect_args: Optional[Dict[str, Any]] = None)¶
Bases:
AdapterConnection
AdapterConnection implementation using the websockets library.
- __init__(url: str, *, headers: Optional[Union[Headers, Mapping[str, str], Iterable[tuple[str, str]], SupportsKeysAndGetItem]] = None, ssl: Union[SSLContext, bool] = False, connect_args: Optional[Dict[str, Any]] = None) None ¶
Initialize the transport with the given parameters.
- Parameters
url – The GraphQL server URL. Example: ‘wss://server.com:PORT/graphql’.
headers – Dict of HTTP Headers.
ssl – ssl_context of the connection. Use ssl=False to disable encryption
connect_args – Other parameters forwarded to websockets.connect
- async send(message: str) None ¶
Send message to the WebSocket server.
- Args:
message: String message to send
- Raises:
TransportConnectionFailed: If connection closed
- async receive() str ¶
Receive message from the WebSocket server.
- Returns:
String message received
- Raises:
TransportConnectionFailed: If connection closed TransportProtocolError: If protocol error or binary data received
- property headers: Optional[Union[Headers, Mapping[str, str], Iterable[tuple[str, str]], SupportsKeysAndGetItem]]¶
Get the response headers from the WebSocket connection.
- Returns:
Dictionary of response headers