Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fix for Hasura using websockets in async_base_client #289

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import enum
import json
import time
from typing import IO, Any, AsyncIterator, Dict, List, Optional, Tuple, TypeVar, cast
from uuid import uuid4

Expand All @@ -9,6 +10,7 @@

from .base_model import UNSET, Upload
from .exceptions import (
GraphQLClientError,
GraphQLClientGraphQLMultiError,
GraphQLClientHttpError,
GraphQLClientInvalidMessageFormat,
Expand Down Expand Up @@ -164,11 +166,17 @@ async def execute_ws(
) as websocket:
await self._send_connection_init(websocket)
# wait for connection_ack from server
await self._handle_ws_message(
await websocket.recv(),
websocket,
expected_type=GraphQLTransportWSMessageType.CONNECTION_ACK,
)
# if ping is received, send pong and continue to wait for connection_ack
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make comment explain that some servers can send ping before connection_ack.

# if connection ack is not recived within 5 seconds raise error
connection_start = time.time()
async for message in websocket:
data = await self._handle_ws_message(message, websocket)
if data and "connection_ack" in data:
break
if time.time() - connection_start > 5:
raise GraphQLClientError(
"Connection ack not received within 5 seconds",
)
await self._send_subscribe(
websocket,
operation_id=operation_id,
Expand Down Expand Up @@ -366,5 +374,7 @@ async def _handle_ws_message(
raise GraphQLClientGraphQLMultiError.from_errors_dicts(
errors_dicts=payload, data=message_dict
)
elif type_ == GraphQLTransportWSMessageType.CONNECTION_ACK:
return {"connection_ack": True}

return None