question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to unsubscribe from graphql-ws subscription

See original GitHub issue

Hello,

When I do a subscription (using graphql-ws fetcher), it works, the results are well printed in the result panel but when I push the stop button, the results stop to be printed on the panel but it seems that nothing is done on the wsClient. GraphiQL does not tell to the wsClient to unsubscribe and events are still sent by the ws server. If I repush the play button, a second subscription using a different UUID is sent to the server on the same websocket connection which if I’m not mistaken is illegal. Is there a way to unsubscribe when the stop button is pressed ? Thx

const URL = "http://debian9acu:8000/graphql";
const URLws = "ws://debian9acu:8000/graphql-ws";
var fetcher = createGraphiQLFetcher( {url:URL,subscriptionUrl:URLws} );
const container = document.getElementById("graphiql");
const defaultQuery = `
{
}
`
render(
  <GraphiQL fetcher={fetcher} defaultQuery={defaultQuery} />,
  container
);

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
n1ru4lcommented, Apr 19, 2021

Hey, this is indeed right, @n1ru4l/push-pull-async-iterable-iterator did not correctly dispose of the sink. I created https://github.com/n1ru4l/push-pull-async-iterable-iterator/pull/54 which should address this. I also published v2.1.3 which has the fix included https://github.com/n1ru4l/push-pull-async-iterable-iterator/releases/tag/v2.1.3

In the meantime, the discussion here will clear whether push-pull-async-iterable-iterator should stay in GraphiQL or not https://github.com/graphql/graphiql/pull/1841#pullrequestreview-639229360

0reactions
JeanLucPonscommented, Feb 25, 2022

Unfortunately I don’t have time to simulate a subscription error that GaphiQL should display but yes it was working when I tested it. With the new client, it the subscription is ok and if you don’t get any ws frame, If I remember well, the interface will stay blank and this is what I expect. Once it receives a ws frame, it decodes it and display it. You can find an exemple of what I can see here: https://gitlab.com/tango-controls/TangoGraphQL/-/tree/master/#subscribing-to-tango-event

Concerning the documentation, a simple client using createGraphiQLFetcher() (as mine) could be useful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Subscriptions - Apollo GraphQL Docs
Apollo Client supports both graphql-ws and subscriptions-transport-ws . ... Determines if your subscription should be unsubscribed and subscribed again.
Read more >
Cancel / Unsubscribe GraphQL Subscription
We use GraphQL subscriptions for the real-time metrics data and show some graphs. ... So the requirement is to cancel the subscription (aka....
Read more >
Handle unsubscribe GraphQL subscription - Stack Overflow
I have an issue with subscription can't be unsubscribe. Before we start, this is my setup: Apollo Client(graphql-ws) <-> Apollo ...
Read more >
Subscriptions | urql Documentation
For backends supporting graphql-ws , we recommend using the graphql-ws client. ... unsubscribe: wsClient.subscribe(operation, sink),.
Read more >
Graphql-ws NPM
Check Graphql-ws 5.11.2 package - Last release 5.11.2 with MIT licence at our NPM ... let unsubscribe = () => { /* complete...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found