cylc-ui icon indicating copy to clipboard operation
cylc-ui copied to clipboard

graphql: send mutations and queries down the websocket?

Open oliver-sanders opened this issue 1 year ago • 0 comments

At present, according to the advice in the ApolloClient docs we split our GraphQL requests so that subscriptions run through the websocket, but queries and mutations run over HTTPS:

https://github.com/cylc/cylc-ui/blob/21d5616dd0428bd274975d22df37187e485efb27/src/graphql/index.js#L133-L140

The stated reason for this is:

in most cases it should continue using HTTP for queries and mutations. This is because queries and mutations don't require a stateful or long-lasting connection, making HTTP more efficient and scalable if a WebSocket connection isn't already present.

Which feels like a flimsy justification since apps which use websockets (like ours) do so for the sake of subscriptions so will almost certainly establish at least one long lived subscription right from the get go. Routing queries and mutations via new HTTPS connections less efficient than using the websocket we already have open.

Note, that at present, there is one (and only one) query which is currently being sent before the websocket is established, the instrospection query. This currently suffers from a lack of retries potentially resulting in a race condition where it may fail causing the UI to lack schema information - #1334 which moving to websockets would actually solve by delaying the request until the connection can be opened according to the websocket retry logic.

oliver-sanders avatar Aug 25 '23 09:08 oliver-sanders