Refactor websockets transports#536
Merged
leszekhanusz merged 9 commits intographql-python:masterfrom Mar 11, 2025
Merged
Conversation
This major architectural improvement implements dependency injection patterns across the WebSockets transport layer, creating a more modular, testable, and extensible system:
- Created abstract AdapterConnection interface in common/adapters/connection.py
- Implemented concrete WebSocketsAdapter to wrap the websockets library
- Moved websockets_base.py to common/base.py maintaining better structure which is independant of the websockets library used
- Added new TransportConnectionClosed exception for clearer error handling
- Reorganized code with proper separation of concerns:
* Moved common functionality into dedicated adapters folder
* Isolated connection handling from transport business logic
* Separated ListenerQueue into its own file for better modularity
Potential Breaking changes:
* New TransportConnectionClosed Exception replacing ConnectionClosed Exception
* websocket attribute removed from transport, now using _connected to
check if the transport is connected
…r Phoenix transport
…r AppSync transport
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #536 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 30 38 +8
Lines 3102 2908 -194
==========================================
- Hits 3102 2908 -194 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #494
This major architectural improvement implements dependency injection patterns across the WebSockets transport layer, creating a more modular, testable, and extensible system:
AdapterConnectioninterface incommon/adapters/connection.pyWebSocketsAdapterto wrap the websockets libraryAIOHTTPWebSocketsAdapterto wrap the aiohttp librarywebsockets_base.pyto:common/base.pyforSubscriptionTransportBaseclass which is generic for all dependencies and all protocolswebsockets_protocol.pyforWebsocketProtocolTransportBasewhich is generic for all dependenciesTransportConnectionFailedexception to trap all exceptions from websockets and aiohttp websockets codePotential Breaking changes:
_connectedinternally to check if the transport is connected