What Happened
In some reasons, I required to write my script through GraphQLClient and develop using Query, Mutation, Subscription. When I developing the subscription I found that when every connection closed and after re-connect, it didn't pass any query operation(StartOperation) to the server. Therefore, everything will no longer be received from the server.
Expected behavior
On re-connected will also able to receive the message from the server.
Version
Additional context
I also checked the source code and found the reason happened in this line.
https://github.com/zino-app/graphql-flutter/blob/master/packages/graphql/lib/src/socket_client.dart#L254
If this line has gone, everything's works fine.
@ryanz1219 can you try and the beta version and see if you still experience the issue
I've tried the 2.1.1-beta.2 and I got the same behavior.
I'm checking to printing something in the onConnect callback (server side). The first time I see how the it's called, but if I make the device lost connection and then connect it again, onConnect is never called
UPDATE:
Testing a little bit more the package, I've realized when you're connecting to the server for the first time, it sends two messages:
type: connection_init and type: start
but when it reconnects it only send type: connection_init
so seems like subscribe isn't called
I've found it's the same issue as https://github.com/zino-app/graphql-flutter/issues/356
@gepd have you found solution?
I've not found a solution yet, I'm looking for something though
I have been away for the last week, I will look into this sometime over the weekend or next week. I am open to any suggestions.
cannot the streamController in the subscribe method (#L238) to reconnect too instead of only close the connection?
I don't know is it have other effects that will cause by removing line 254 in the before I said, but I am trying to remove this line because SocketClient._connect() called at the beginning and _connect() will auto re-connect the server according to the same file at line 140.
However, the connection is reconnected by line 140 but It didn't resend the previous GraphQL operation to the server caused by line 254 so the WebSocket is connected, graphql operation isn't started in server cause by request isn't sent.
I hope this information will helpful for this problem.
cannot the streamController in the
subscribemethod (#L238) to reconnect too instead of only close the connection?
I think it can't because the subscribe method is directly called by the user so if reconnect it, then the user will be required to reload their subscription callback also.
In addition, the streamController doesn't know any network status of the connection at now. streamController depends on _connectionStateController to receive a new message for itself.
As my knowledge :)
Hey @mainawycliffe have you been able to check this? If so, what are your thought about it? It seems like it isn't an easy fix without breaking the current functioning
I am sorry, this is another that slipped my radar. I am thinking we could probably have a queue for all Subscription operations and upon reconnection, retry them again. When the connection fails, does it send an error and close the subscription? I currently don't have any way of testing this, so I will have to create a demo to see this behavior my self.
I tweaked it for my project a few months ago until waiting for this to be fixed. Not perfect solution, but may be helpful
https://github.com/EugenePisotsky/graphql-flutter/commit/57f64c37fdc895d822d0c713b3c7d21630613498
Idea is to create map of subscriptions with callbacks that call response.onListen each time after websocket connection is restored
@EugenePisotsky If it's already working for you, can you PR the change and we will review and merge it. Here are our contributing guidelines.
@mainawycliffe Ok, I'll try to find time within the next few days
@EugenePisotsky did you get a chance to get a PR in for this? Subscriptions are pointless without it.
@kulture-rob
done. if someone has a better solution it would be awesome :)
:tada: This issue has been resolved in version 2.1.1-beta.5 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket:
I am closing this issue, the PR has been released to the latest beta.
:tada: This issue has been resolved in version 3.0.0-beta.1 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket:
:tada: This issue has been resolved in version 3.0.0 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket:
Most helpful comment
@mainawycliffe Ok, I'll try to find time within the next few days