Skip to content

Refactor websockets transports #536

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

Merged

Conversation

leszekhanusz
Copy link
Collaborator

@leszekhanusz leszekhanusz commented Mar 9, 2025

Issue #494

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 WebSocketsAdapter to wrap the websockets library
    • Implemented AIOHTTPWebSocketsAdapter to wrap the aiohttp library
  • Moved websockets_base.py to:
    • common/base.py for SubscriptionTransportBase class which is generic for all dependencies and all protocols
    • websockets_protocol.py for WebsocketProtocolTransportBase which is generic for all dependencies
  • Added new TransportConnectionFailed exception to trap all exceptions from websockets and aiohttp websockets code
  • Reorganized code with proper separation of concerns:
    • Moved common functionality into common folder
    • Isolated connection handling from transport business logic
    • Separated ListenerQueue into its own file

Potential Breaking changes:

  • New TransportConnectionFailed Exception replacing specific websockets and aiohttp exceptions
  • websocket attribute removed from transport, now using _connected internally to check if the transport is connected

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
Copy link

codecov bot commented Mar 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (57ef910) to head (7fb869a).
Report is 36 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leszekhanusz leszekhanusz merged commit a150161 into graphql-python:master Mar 11, 2025
15 checks passed
@leszekhanusz leszekhanusz deleted the chore_refactor_websockets branch March 11, 2025 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant