[gql_websocket_link] enhancement for websocket connection errors
Background
Hi Team,
This PR is recreated from https://github.com/gql-dart/gql/pull/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<ConnectionError> _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.
@agent3bood are you able to triage this? I'm not actively using the websocket so I cannot say too much about this
@dehypnosis Thanks for the second PR, I ned to take a closer look at it. By reading our current code I can see other possible improvements to be made.