Skip to content

Commit fe6712b

Browse files
committed
Using SubscriptionTransportBase instead of WebsocketsTransportBase for AppSync transport
1 parent 4a8493b commit fe6712b

1 file changed

Lines changed: 34 additions & 7 deletions

File tree

gql/transport/appsync_websockets.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
from graphql import DocumentNode, ExecutionResult, print_ast
88

99
from .appsync_auth import AppSyncAuthentication, AppSyncIAMAuthentication
10+
from .common.adapters.websockets import WebSocketsAdapter
11+
from .common.base import SubscriptionTransportBase
1012
from .exceptions import TransportProtocolError, TransportServerError
11-
from .websockets import WebsocketsTransport, WebsocketsTransportBase
13+
from .websockets import WebsocketsTransport
1214

1315
log = logging.getLogger("gql.transport.appsync")
1416

@@ -19,7 +21,7 @@
1921
pass
2022

2123

22-
class AppSyncWebsocketsTransport(WebsocketsTransportBase):
24+
class AppSyncWebsocketsTransport(SubscriptionTransportBase):
2325
""":ref:`Async Transport <async_transports>` used to execute GraphQL subscription on
2426
AWS appsync realtime endpoint.
2527
@@ -32,6 +34,7 @@ class AppSyncWebsocketsTransport(WebsocketsTransportBase):
3234
def __init__(
3335
self,
3436
url: str,
37+
*,
3538
auth: Optional[AppSyncAuthentication] = None,
3639
session: Optional["botocore.session.Session"] = None,
3740
ssl: Union[SSLContext, bool] = False,
@@ -70,17 +73,25 @@ def __init__(
7073
auth = AppSyncIAMAuthentication(host=host, session=session)
7174

7275
self.auth = auth
76+
self.ack_timeout: Optional[Union[int, float]] = ack_timeout
77+
self.init_payload: Dict[str, Any] = {}
7378

7479
url = self.auth.get_auth_url(url)
7580

76-
super().__init__(
77-
url,
81+
# Instanciate a WebSocketAdapter to indicate the use
82+
# of the websockets dependency for this transport
83+
self.adapter: WebSocketsAdapter = WebSocketsAdapter(
84+
url=url,
7885
ssl=ssl,
86+
connect_args=connect_args,
87+
)
88+
89+
# Initialize the generic SubscriptionTransportBase parent class
90+
super().__init__(
91+
adapter=self.adapter,
7992
connect_timeout=connect_timeout,
8093
close_timeout=close_timeout,
81-
ack_timeout=ack_timeout,
8294
keep_alive_timeout=keep_alive_timeout,
83-
connect_args=connect_args,
8495
)
8596

8697
# Using the same 'graphql-ws' protocol as the apollo protocol
@@ -181,7 +192,7 @@ async def _send_query(
181192

182193
return query_id
183194

184-
subscribe = WebsocketsTransportBase.subscribe # type: ignore[assignment]
195+
subscribe = SubscriptionTransportBase.subscribe # type: ignore[assignment]
185196
"""Send a subscription query and receive the results using
186197
a python async generator.
187198
@@ -212,3 +223,19 @@ async def execute(
212223
WebsocketsTransport._send_init_message_and_wait_ack
213224
)
214225
_wait_ack = WebsocketsTransport._wait_ack
226+
227+
@property
228+
def url(self) -> str:
229+
return self.adapter.url
230+
231+
@property
232+
def headers(self) -> Dict[str, str]:
233+
return self.adapter.headers
234+
235+
@property
236+
def ssl(self) -> Union[SSLContext, bool]:
237+
return self.adapter.ssl
238+
239+
@property
240+
def connect_args(self) -> Dict[str, Any]:
241+
return self.adapter.connect_args

0 commit comments

Comments
 (0)