Skip to content

Switch to graphql-transport-ws subprotocol - #821

Open
MetRonnie wants to merge 5 commits into
cylc:masterfrom
MetRonnie:graphql-transport-ws
Open

Switch to graphql-transport-ws subprotocol#821
MetRonnie wants to merge 5 commits into
cylc:masterfrom
MetRonnie:graphql-transport-ws

Conversation

@MetRonnie

@MetRonnie MetRonnie commented May 13, 2026

Copy link
Copy Markdown
Member

Closes #690

Implements the graphql-transport-ws subprotocol as defined in https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md

Sibling: cylc/cylc-ui#2548

Check List

  • I have read CONTRIBUTING.md and added my name as a Code Contributor.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • No dependency changes
  • Tests are included (or explain why tests are not needed).
  • Changelog entry included if this is a change that can affect users
  • Cylc-Doc pull request opened if required at cylc/cylc-doc/pull/XXXX.
  • If this is a bug fix, PR should be raised against the relevant ?.?.x branch.

@MetRonnie MetRonnie added this to the 1.10.0 milestone May 13, 2026
@MetRonnie MetRonnie self-assigned this May 13, 2026
@MetRonnie
MetRonnie force-pushed the graphql-transport-ws branch from feb91ec to 9d7c5f8 Compare June 12, 2026 13:52
@MetRonnie
MetRonnie marked this pull request as ready for review June 12, 2026 14:50
@MetRonnie
MetRonnie requested a review from Copilot June 30, 2026 10:15
@MetRonnie

Copy link
Copy Markdown
Member Author

Requested a review from Copilot to try this out for the first time...

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Switches the UI Server’s WebSocket GraphQL subscriptions to the graphql-transport-ws subprotocol and updates the server-side message handling to follow the newer protocol semantics.

Changes:

  • Updated subscription WebSocket protocol constant and message handling (graphql-transport-ws, new message types, ping/pong, subscribe/next/complete).
  • Simplified subscription handler state management by making sub_statuses handler-local and updated resolvers context wiring accordingly.
  • Updated tests and added a changelog entry for the protocol change.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
cylc/uiserver/tests/test_handlers.py Updates the subprotocol selection test to the new protocol.
cylc/uiserver/handlers.py Switches the selected WebSocket subprotocol constant and adjusts subscription handler initialization/state.
cylc/uiserver/graphql/tornado_ws.py Implements graphql-transport-ws message types and updates subscription server message processing logic.
cylc/uiserver/authorise.py Tightens typing for AuthorizationMiddleware.auth.
cylc/uiserver/app.py Removes app-level sub_statuses plumbing now that subscription status is handler-local.
changes.d/821.feat.md Documents the protocol change in the changelog.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cylc/uiserver/handlers.py
Comment on lines 389 to +390
def select_subprotocol(self, subprotocols):
return GRAPHQL_WS
return WS_PROTOCOL

@MetRonnie MetRonnie Jun 30, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are simultaneously upgrading the client (cylc/cylc-ui#2548) so this is not a problem (apart from the awkwardness of running development UI/UIS for a while when different branches have different subprotocols)

Comment on lines +222 to +224
if not isinstance(payload, dict):
raise AssertionError("The payload must be a dict")
assert op_id, "The message must have an operation ID"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be resolved by this I suppose

diff --git a/cylc/uiserver/graphql/tornado_ws.py b/cylc/uiserver/graphql/tornado_ws.py
index ffb9ebe..faebd89 100644
--- a/cylc/uiserver/graphql/tornado_ws.py
+++ b/cylc/uiserver/graphql/tornado_ws.py
@@ -436,7 +436,6 @@ class TornadoSubscriptionServer:
             if not isinstance(parsed_message, dict):
                 raise AssertionError("Message must be an object")
+            self.process_message(connection_context, parsed_message)
         except Exception as e:
             connection_context.ws.close(4400, str(e))
             return None
-
-        self.process_message(connection_context, parsed_message)

await self.on_subscribe(connection_context, op_id, params)

case OperationType.COMPLETE.value:
assert op_id, "The message must have an operation ID"
Comment thread cylc/uiserver/tests/test_handlers.py
Comment thread cylc/uiserver/graphql/tornado_ws.py Outdated
@MetRonnie
MetRonnie force-pushed the graphql-transport-ws branch from d87a94c to 029fd70 Compare July 21, 2026 12:36
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.

websocket: change subprotocol

2 participants