[gql_websocket_link] enhancement for websocket connection errors #412
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
Hi Team,
This PR is recreated from #388 due to lack of feedbacks and a branch issue from my side. Please check original threads because there were some feedbacks and patch history for that (@agent3bood @knaeckeKami).
Resolved issues
1. Subscription stream become broken when got WebSocketChannelException.
Currently Subscription request is losing message streams when the client got WebSocketChannelException.
And this problem is cannot be recovered automatically when even autoReconnect is on and so the websocket connection recovered. It means when client have a connection problem, all message stream subscriptions for 'Subscription Operation' should be manually recreated (by navigating routes or whatever)
Fixed this issue by not closing message subscription on WebSocketChannelException.
2. No way to get ConnectionError directly from application.
Added StreamController _connectionErrorController and public accessor connectionErrorStream.
A practical use case is that, when web socket connection failed due to server side decision or unexpected error, client can be notified about detail of error to take some action.
For example from my case, I need to refresh my client-side id token when it has expired. while I am using Firebase Authentication, It can be detected on App startup logic. But when id token became inactive while using app, my server will close the connection with error message to make the app to refresh token. But there were no way for client to detect connection issue.
Note
I made this patches to deal with above cases and any other server-side connection errors.
And both fixes are working on production for six months without an issue.
Thank you for reviewing it.