Skip to content

Resubscribe on Error Message #435

Answered by enisdenjo
zhixinwen asked this question in Q&A
Discussion options

You must be logged in to vote

Maybe I am not understanding your question, but why not literally re-subscribe on error? Roughly:

import { createClient } from 'graphql-ws';

const client = createClient({
  url: 'ws://unstable:4000/graphql',
});

(async () => {
  for (;;) {
    try {
      await new Promise((resolve, reject) => {
        client.subscribe(
          {
            query: 'subscription { iMightFail }',
          },
          {
            next: (val) => {
              console.log(val); // or emit the value however you want
            },
            error: reject,
            complete: resolve,
          },
        );
      });
      // subscription has completed successfully, break the loop to avoid subsc…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@zhixinwen
Comment options

@AaronBuxbaum
Comment options

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