apollographql / apollo-ios

📱  A strongly-typed, caching GraphQL client for iOS, written in Swift.
https://www.apollographql.com/docs/ios/
MIT License
3.86k stars 714 forks source link

How to know subscription state #3344

Open arnauddorgans opened 6 months ago

arnauddorgans commented 6 months ago

Question

Hi

Is there a way to know the current state or listen to the state change of a subscription?

Sometimes, I feel that after a socket disconnection, there is a delay between the actual resubscription, and I would like to make sure that a specific subscription is currently listening or reconnecting, etc..

calvincestari commented 6 months ago

Hi @arnauddorgans - there unfortunately isn't any way to get the status of a single subscription.

The current implementation is very naive with regards to it's implementation of subscribers. There is a list of subscribers keyed by an identifier with no state being stored about the subscriptions. I suppose if a subscriber identifier is in that list it could be considered 'open' but for identifiers that are not present we'd have no idea if that had even a valid identifier so it would be incorrect to return 'closed' when it could have been 'never existed'.

There is probably a hacky solution we could implement to enable this for now but 2.0 is really where we'll improve everything networking.

WebSocketTransportDelegate will give you connection events for WebSocketTransport so you could use this as a sort of proxy indicator if you only have a single subscription, but if you use the same websocket transport for multiple subscriptions then that will not work.