Skip to content

Commit ea8b21f

Browse files
graphql-ws: migrate from grahphql-transport-ws to graphql-ws
* The graphql-transport-ws library is no longer maintained. * Move to grahpql-ws. * Closes cylc#1028
1 parent 99bf482 commit ea8b21f

File tree

3 files changed

+29
-69
lines changed

3 files changed

+29
-69
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"nprogress": "1.0.0-1",
4242
"preact": "10.16.0",
4343
"preact-compat": "3.19.0",
44-
"subscriptions-transport-ws": "0.11.0",
4544
"svg-pan-zoom": "3.6.1",
4645
"vue": "3.3.4",
4746
"vue-i18n": "9.2.2",

src/graphql/index.js

+28-23
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import {
2222
InMemoryCache,
2323
split
2424
} from '@apollo/client/core'
25+
import { GraphQLWsLink } from '@apollo/client/link/subscriptions'
2526
import { getMainDefinition } from '@apollo/client/utilities'
26-
import { WebSocketLink } from '@apollo/client/link/ws'
2727
import { setContext } from '@apollo/client/link/context'
28-
import { SubscriptionClient } from 'subscriptions-transport-ws'
28+
import { createClient } from 'graphql-ws'
2929
import { store } from '@/store/index'
3030
import { createUrl } from '@/utils/urls'
3131

@@ -72,27 +72,32 @@ export function getCylcHeaders () {
7272
* @return {SubscriptionClient} a subscription client
7373
*/
7474
export function createSubscriptionClient (wsUrl, options = {}, wsImpl = null) {
75-
const opts = Object.assign({
76-
reconnect: true,
77-
lazy: false
78-
}, options)
79-
const subscriptionClient = new SubscriptionClient(wsUrl, opts, wsImpl)
80-
// these are the available hooks in the subscription client lifecycle
81-
subscriptionClient.onConnecting(() => {
82-
store.commit('SET_OFFLINE', true)
83-
})
84-
subscriptionClient.onConnected(() => {
85-
store.commit('SET_OFFLINE', false)
86-
})
87-
subscriptionClient.onReconnecting(() => {
88-
store.commit('SET_OFFLINE', true)
89-
})
90-
subscriptionClient.onReconnected(() => {
91-
store.commit('SET_OFFLINE', false)
92-
})
93-
subscriptionClient.onDisconnected(() => {
94-
store.commit('SET_OFFLINE', true)
75+
const subscriptionClient = createClient({
76+
url: wsUrl,
77+
shouldRetry: () => true,
78+
retryAttempts: 999999999999999,
79+
retryWait: async function waitForServerHealthyBeforeRetry () {
80+
// this is called when the connection fails
81+
// wait 2 seconds, then retry
82+
await new Promise((resolve) => setTimeout(resolve, 500))
83+
},
84+
on: {
85+
connecting: () => {
86+
store.commit('SET_OFFLINE', true)
87+
},
88+
connected: (socket, payload) => {
89+
store.commit('SET_OFFLINE', false)
90+
},
91+
closed: (event) => {
92+
store.commit('SET_OFFLINE', true)
93+
},
94+
error: (error) => {
95+
console.error(error)
96+
store.commit('SET_OFFLINE', true)
97+
},
98+
}
9599
})
100+
96101
// TODO: at the moment the error displays an Event object, but the browser also displays the problem, as well as the offline indicator
97102
// would be nice to find a better error message using the error object
98103
// subscriptionClient.onError((error) => {
@@ -127,7 +132,7 @@ export function createApolloClient (httpUrl, subscriptionClient) {
127132
})
128133

129134
const wsLink = subscriptionClient !== null
130-
? new WebSocketLink(subscriptionClient)
135+
? new GraphQLWsLink(subscriptionClient)
131136
: new ApolloLink() // return an empty link, useful for testing, offline mode, etc
132137

133138
const link = split(

yarn.lock

+1-45
Original file line numberDiff line numberDiff line change
@@ -2827,13 +2827,6 @@ __metadata:
28272827
languageName: node
28282828
linkType: hard
28292829

2830-
"backo2@npm:^1.0.2":
2831-
version: 1.0.2
2832-
resolution: "backo2@npm:1.0.2"
2833-
checksum: fda8d0a0f4810068d23715f2f45153146d6ee8f62dd827ce1e0b6cc3c8328e84ad61e11399a83931705cef702fe7cbb457856bf99b9bd10c4ed57b0786252385
2834-
languageName: node
2835-
linkType: hard
2836-
28372830
"balanced-match@npm:^1.0.0":
28382831
version: 1.0.2
28392832
resolution: "balanced-match@npm:1.0.2"
@@ -3644,7 +3637,6 @@ __metadata:
36443637
sass: 1.64.2
36453638
sinon: 15.2.0
36463639
standard: 17.1.0
3647-
subscriptions-transport-ws: 0.11.0
36483640
svg-pan-zoom: 3.6.1
36493641
vite: 4.4.8
36503642
vite-plugin-eslint: 1.8.1
@@ -5028,13 +5020,6 @@ __metadata:
50285020
languageName: node
50295021
linkType: hard
50305022

5031-
"eventemitter3@npm:^3.1.0":
5032-
version: 3.1.2
5033-
resolution: "eventemitter3@npm:3.1.2"
5034-
checksum: 81e4e82b8418f5cfd986d2b4a2fa5397ac4eb8134e09bcb47005545e22fdf8e9e61d5c053d34651112245aae411bdfe6d0ad5511da0400743fef5fc38bfcfbe3
5035-
languageName: node
5036-
linkType: hard
5037-
50385023
"execa@npm:4.1.0":
50395024
version: 4.1.0
50405025
resolution: "execa@npm:4.1.0"
@@ -6638,13 +6623,6 @@ __metadata:
66386623
languageName: node
66396624
linkType: hard
66406625

6641-
"iterall@npm:^1.2.1":
6642-
version: 1.3.0
6643-
resolution: "iterall@npm:1.3.0"
6644-
checksum: c78b99678f8c99be488cca7f33e4acca9b72c1326e050afbaf023f086e55619ee466af0464af94a0cb3f292e60cb5bac53a8fd86bd4249ecad26e09f17bb158b
6645-
languageName: node
6646-
linkType: hard
6647-
66486626
"jju@npm:^1.1.0":
66496627
version: 1.4.0
66506628
resolution: "jju@npm:1.4.0"
@@ -9535,21 +9513,6 @@ __metadata:
95359513
languageName: node
95369514
linkType: hard
95379515

9538-
"subscriptions-transport-ws@npm:0.11.0":
9539-
version: 0.11.0
9540-
resolution: "subscriptions-transport-ws@npm:0.11.0"
9541-
dependencies:
9542-
backo2: ^1.0.2
9543-
eventemitter3: ^3.1.0
9544-
iterall: ^1.2.1
9545-
symbol-observable: ^1.0.4
9546-
ws: ^5.2.0 || ^6.0.0 || ^7.0.0
9547-
peerDependencies:
9548-
graphql: ^15.7.2 || ^16.0.0
9549-
checksum: cc2e98d5c9d89c44d2e15eca188781c6ebae13d1661c42a99cee9d2897aebe2a22bc118eefff83244a79c88ee4ea24d46973ebf26ae7cb47ac1857fb8ee2c947
9550-
languageName: node
9551-
linkType: hard
9552-
95539516
"supports-color@npm:^5.3.0, supports-color@npm:^5.5.0":
95549517
version: 5.5.0
95559518
resolution: "supports-color@npm:5.5.0"
@@ -9591,13 +9554,6 @@ __metadata:
95919554
languageName: node
95929555
linkType: hard
95939556

9594-
"symbol-observable@npm:^1.0.4":
9595-
version: 1.2.0
9596-
resolution: "symbol-observable@npm:1.2.0"
9597-
checksum: 48ffbc22e3d75f9853b3ff2ae94a44d84f386415110aea5effc24d84c502e03a4a6b7a8f75ebaf7b585780bda34eb5d6da3121f826a6f93398429d30032971b6
9598-
languageName: node
9599-
linkType: hard
9600-
96019557
"symbol-observable@npm:^4.0.0":
96029558
version: 4.0.0
96039559
resolution: "symbol-observable@npm:4.0.0"
@@ -10678,7 +10634,7 @@ __metadata:
1067810634
languageName: node
1067910635
linkType: hard
1068010636

10681-
"ws@npm:^5.2.0 || ^6.0.0 || ^7.0.0, ws@npm:^7.4.6":
10637+
"ws@npm:^7.4.6":
1068210638
version: 7.5.8
1068310639
resolution: "ws@npm:7.5.8"
1068410640
peerDependencies:

0 commit comments

Comments
 (0)