apollo-kotlin
apollo-kotlin copied to clipboard
Add a way to get info about the websocket connexion status
Use case
We are building a messaging SDK on top of Apollo and we would like to expose a state of the websocket connexion so that we can display in the UI when we are offline. This would be useful to let the user know that they won't receive messages live until they have network again.
Describe the solution you'd like
Right now the only solution I found is to implement my own WebSocketEngine
and provide it to Apollo
. But I ended up copy/pasting basically all the code from OkHttpWebSocketEngine
and it's not really futureproof.
Hi @benoitletondor and others👋
@benoitletondor I know you've moved from this issue but I've spent some time with it recently and I wonder how much it makes sense to have a "per-websocket" status vs a "per-subscription" status.
As more and more incremental delivery is managed outside of websockets, it feels a bit weird to add code that is specific to WebSockets. For an example, multipart subscriptions would not be able to use this despite exposing the same kind of functionality.
Would it make sense to have a special event in the Flow
to indicate connection/disconnection
instead?
sealed interface SubscriptionItem
class SubscriptionResponse(val data: D, val errors: List<Error>): SusbcriptionItem
class SubscriptionError(val exception: ApolloException): SusbcriptionItem
class SubscriptionConnected(): SusbcriptionItem
class SubscriptionDisconnected(): SusbcriptionItem
fun ApolloSubscriptionCall.toFlow(): Flow<SubscriptionItem> {
}
If you can remember, would that have worked for you? Or did you explicitely need the websocket status?
Hi @martinbonnin ! That makes sense to me, using the websocket was my way of achieving this but indeed I'm interested in knowing the status of the subscription (aka will I receive events or not) so it works
Thanks for the quick reply ❤️ !
For the record, a use case for a SubscriptionConnected
event is there: https://medium.com/@admund88/migration-from-aws-mobile-appsync-to-raw-appolo-graphql-v3-on-android-d5d8e7b3344c
IIUC, the subscription is started from the result of a mutation but if something changed before SubscriptionConnected
, the mutation needs to be run again (which still feels racy to me but I understand the event can be use to decrease the probability of a race).