Akryum / Akryum/vue-cli-plugin-apollo

restartWebsockets does not properly re-open the WebSocket connection

Đang mở
#367 4 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
477
Fork
109
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

The graphql-client function `restartWebsockets` is called during the `onLogin` and `onLogout` functions provided by the `vue-apollo.js` template in order to update the authentication header of the WebSocket connection.
https://github.com/Akryum/vue-cli-plugin-apollo/blob/d9fe48c61cc19db88fef4e4aa5e49b31aa0c44b7/generator/templates/vue-apollo/default/src/vue-apollo.js#L80-L106

`restartWebsockets` force-closes the current WebSocket connection, opens a new one, and attempts to push all existing subscriptions to the new connection.
https://github.com/Akryum/vue-cli-plugin-apollo/blob/d9fe48c61cc19db88fef4e4aa5e49b31aa0c44b7/graphql-client/src/index.js#L194-L212

However, manually sending `GQL_START` messages serves only to restore the WebSocket messages. The message handlers, which were destroyed by `wsClient.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`](https://github.com/apollographql/subscriptions-transport-ws):
- [`SubscriptionClient.close`](https://github.com/apollographql/subscriptions-transport-ws/blob/567fca89cb4578371877faee09e1630dcddff544/src/client.ts#L152-L173) calls [`SubscriptionClient.unsubscribeAll`](https://github.com/apollographql/subscriptions-transport-ws/blob/567fca89cb4578371877faee09e1630dcddff544/src/client.ts#L161)
- [`SubscriptionClient.unsubscribeAll`](https://github.com/apollographql/subscriptions-transport-ws/blob/567fca89cb4578371877faee09e1630dcddff544/src/client.ts#L255-L259) calls [`SubscriptionClient.unsubscribe`](https://github.com/apollographql/subscriptions-transport-ws/blob/567fca89cb4578371877faee09e1630dcddff544/src/client.ts#L257) on each operation (subscription)
- [`SubscriptionClient.unsubscribe`](https://github.com/apollographql/subscriptions-transport-ws/blob/567fca89cb4578371877faee09e1630dcddff544/src/client.ts#L661-L667) [deletes the operation](https://github.com/apollographql/subscriptions-transport-ws/blob/567fca89cb4578371877faee09e1630dcddff544/src/client.ts#L663)
- After `restartWebsockets` manually reinstates the WebSocket messages using `GQL_START`, messages begin to arrive
- [`SubscriptionClient.processReceivedData`](https://github.com/apollographql/subscriptions-transport-ws/blob/567fca89cb4578371877faee09e1630dcddff544/src/client.ts#L585-L659) attempts to call the handler for the operation, but the operation does not exist, as it was deleted by the `unsubscribe` call.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.