Skip to content

How to unsubscribe a subscription using graphql-ws with apollo client #132

Answered by enisdenjo
edwardfeng-db asked this question in Q&A
Discussion options

You must be logged in to vote

Hey there, the Complete message is sent when the subscription is done with. You dont explicitly send the message, you unsubscribe from a subscription.

const unsubscribe = client.subscribe(
  {
    query: 'subscription { greetings }',
  },
  {
    next: onNext,
    error: onError,
    complete: onComplete,
  },
);

// calling `unsubscribe` will send a `Complete` message for the subscription
unsubscribe();

Regarding your question about subscribeToMore - I actually have no idea about its inner workings (and I also have 0 experience with the Apollo stack), I am sorry, but I cannot be of any help there. 😬

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@edwardfeng-db
Comment options

@enisdenjo
Comment options

Answer selected by edwardfeng-db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants