router icon indicating copy to clipboard operation
router copied to clipboard

refactor(subscription): consolidate WebSocket handling in subscription plugin

Open BrynCooke opened this issue 5 months ago • 2 comments

Consolidate WebSocket handling in subscription plugin

Task

Consolidate WebSocket subscription handling logic within the subscription plugin to improve architectural clarity and code maintainability as part of the broader subgraph service refactoring effort.

Why

The WebSocket subscription logic was scattered between the subgraph service and subscription plugin, creating unnecessary coupling and making the codebase harder to maintain. WebSocket handling is subscription-specific functionality that logically belongs entirely within the subscription plugin rather than being split across multiple services.

Benefits:

  • Clear ownership of WebSocket subscription logic within subscription plugin
  • Reduced coupling between subgraph service and subscription functionality
  • Better separation of concerns following single responsibility principle
  • Foundation for future subscription protocol enhancements

How

Code Consolidation:

  • Moved call_websocket() and get_websocket_request() functions from subgraph service to subscription plugin
  • Relocated SubscriptionExtension struct definition to subscription plugin module
  • Updated subgraph service to delegate WebSocket subscription requests to subscription plugin
  • Removed unused WebSocket imports and dependencies from subgraph service

Architectural Improvements:

  • Subscription plugin now owns all subscription-related WebSocket logic
  • Subgraph service focuses solely on HTTP request handling
  • Reduced coupling between services while preserving all existing functionality

Technical Details

  • Zero behavioral changes: All WebSocket subscription functionality remains identical
  • API compatibility: Fully preserved with no breaking changes
  • Code organization: Complete separation of HTTP and WebSocket concerns
  • Import cleanup: Removed unused WebSocket dependencies from subgraph service
  • Delegation pattern: Subgraph service cleanly delegates to subscription plugin for WebSocket requests

Review Strategy

Focus on these specific areas not covered by CI:

  1. Functional verification: Confirm that all WebSocket subscription functionality works identically to before, including error handling and connection management

  2. Architecture review: Verify that the subscription plugin properly handles all WebSocket scenarios that were previously handled by subgraph service

  3. Code organization: Check that no subscription-related logic remains in subgraph service and that all imports are properly updated

  4. Delegation correctness: Ensure that the subgraph service properly identifies and delegates WebSocket requests to the subscription plugin without data loss

  5. Test coverage: Verify that all existing WebSocket subscription tests pass and that no functionality was lost during the code movement


Checklist

Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.

  • [ ] Changes are compatible[^1]
  • [ ] Documentation[^2] completed
  • [ ] Performance impact assessed and acceptable
  • [ ] Metrics and logs are added[^3] and documented
  • Tests added and passing[^4]
    • [ ] Unit Tests
    • [ ] Integration Tests
    • [ ] Manual Tests

Exceptions

Note any exceptions here

Notes

[^1]: It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this. [^2]: Configuration is an important part of many changes. Where applicable please try to document configuration examples. [^3]: A lot of (if not most) features benefit from built-in observability and debug-level logs. Please read this guidance on metrics best-practices. [^4]: Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions.

BrynCooke avatar Jun 14 '25 19:06 BrynCooke

@BrynCooke, please consider creating a changeset entry in /.changesets/. These instructions describe the process and tooling.

github-actions[bot] avatar Jun 14 '25 19:06 github-actions[bot]

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: 6bf77d65a00effee68fd52ce

apollo-librarian[bot] avatar Jun 14 '25 22:06 apollo-librarian[bot]