-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
restartWebsockets does not properly re-open the WebSocket connection #367
Comments
@jake-leland I think I have the same problem, did you find a solution or workaround for this? |
@jake-leland @heivo I also have the same issue and would love to know whether you found a workaround? |
I think I have just found a workaround which is just to call subscribe again after the websocket is restarted. I do this by adding a variable (which is not needed) in my subscribeToMore: {
document: onRoomUpdated,
variables() {
// Adding meId as a fake variable to force it to re-subscribe when we login
return { id: this.roomId, meId: this.me.id }
},
... So this means that after I login, it fetches the me variable and then when that updates Vue detects the change and subscribes again. |
@aullman's approach is the simplest workaround I've found. With this workaround, the subscribeToMore: {
...
skip() {
return this.me?.id == null
},
...
} The only other workaround I had tried was to modify the |
The graphql-client function
restartWebsockets
is called during theonLogin
andonLogout
functions provided by thevue-apollo.js
template in order to update the authentication header of the WebSocket connection.vue-cli-plugin-apollo/generator/templates/vue-apollo/default/src/vue-apollo.js
Lines 80 to 106 in d9fe48c
restartWebsockets
force-closes the current WebSocket connection, opens a new one, and attempts to push all existing subscriptions to the new connection.vue-cli-plugin-apollo/graphql-client/src/index.js
Lines 194 to 212 in d9fe48c
However, manually sending
GQL_START
messages serves only to restore the WebSocket messages. The message handlers, which were destroyed bywsClient.close
, are never restored. Because of this, the Vue-Apollo smart queries/subscriptions will no longer receive updates. A manual refresh of the page is required to fully restore the subscriptions.Details in
subscriptions-transport-ws
:SubscriptionClient.close
callsSubscriptionClient.unsubscribeAll
SubscriptionClient.unsubscribeAll
callsSubscriptionClient.unsubscribe
on each operation (subscription)SubscriptionClient.unsubscribe
deletes the operationrestartWebsockets
manually reinstates the WebSocket messages usingGQL_START
, messages begin to arriveSubscriptionClient.processReceivedData
attempts to call the handler for the operation, but the operation does not exist, as it was deleted by theunsubscribe
call.The text was updated successfully, but these errors were encountered: