Skip to content

Commit 352af37

Browse files
committed
Put dependency-free websockets protocol in websockets_protocol.py
1 parent fe6712b commit 352af37

9 files changed

Lines changed: 564 additions & 557 deletions

File tree

gql/transport/appsync_websockets.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,6 @@ async def execute(
224224
)
225225
_wait_ack = WebsocketsTransport._wait_ack
226226

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-
235227
@property
236228
def ssl(self) -> Union[SSLContext, bool]:
237229
return self.adapter.ssl
238-
239-
@property
240-
def connect_args(self) -> Dict[str, Any]:
241-
return self.adapter.connect_args

gql/transport/common/adapters/connection.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import abc
2-
from typing import Dict
2+
from typing import Any, Dict
33

44

55
class AdapterConnection(abc.ABC):
@@ -8,6 +8,9 @@ class AdapterConnection(abc.ABC):
88
This allows different WebSocket implementations to be used interchangeably.
99
"""
1010

11+
url: str
12+
connect_args: Dict[str, Any]
13+
1114
@abc.abstractmethod
1215
async def connect(self) -> None:
1316
"""Connect to the server."""

gql/transport/common/adapters/websockets.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(
1919
*,
2020
headers: Optional[HeadersLike] = None,
2121
ssl: Union[SSLContext, bool] = False,
22-
connect_args: Dict[str, Any] = {},
22+
connect_args: Optional[Dict[str, Any]] = None,
2323
) -> None:
2424
"""Initialize the transport with the given parameters.
2525
@@ -31,6 +31,10 @@ def __init__(
3131
self.url: str = url
3232
self._headers: Optional[HeadersLike] = headers
3333
self.ssl: Union[SSLContext, bool] = ssl
34+
35+
if connect_args is None:
36+
connect_args = {}
37+
3438
self.connect_args = connect_args
3539

3640
self.websocket: Optional[WebSocketClientProtocol] = None

gql/transport/common/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,11 @@ async def wait_closed(self) -> None:
559559
log.debug("Timer close_timeout fired in wait_closed")
560560

561561
log.debug("wait_close: done")
562+
563+
@property
564+
def url(self) -> str:
565+
return self.adapter.url
566+
567+
@property
568+
def connect_args(self) -> Dict[str, Any]:
569+
return self.adapter.connect_args

0 commit comments

Comments
 (0)