Based on this topic: Is it possible to cancel Graphql subscriptions?.
I was using useSubscription
, but when I came across the topic above, I changed it to the client.subscribe()
implementation to manually unsubscribe.
However, after unsubscribing using subscription.unsubscribe();
, I noticed that the web socket is still opened and still listening to events. So my question is, how do I disconnect the observer?
I am guessing it should look something like this: observer.disconnect();
.
Hi! Your WebSocketLink
instance exposes a subscriptionClient
object that you can call close()
on:
const webSocketLink = new WebSocketLink({
uri: '...',
options: {},
});
webSocketLink.subscriptionClient.close();
@mindnektar Thank you for your response, I am using AbsintheSocket
, and PhoenixSocket
for my connection, so here is how it looks:
const absintheSocketLink = createAbsintheSocketLink(
AbsintheSocket.create(
new PhoenixSocket('ws://auth.localhost.test/socket', {
params: {params},
})
)
);
const AccountSocketClient = new ApolloClient({
link: absintheSocketLink,
cache: new InMemoryCache(),
});
AccountSocketClient is the apollo client I use to subscribe.
Have you tried AbsintheSocket.cancel? Otherwise I’d suggest asking the maintainers of that library, they can probably help.
Yes, I tried that. But, unfortunately, it didn’t seem to work.