Skip to content

Timeout for queries/mutation - backend does not response causing an infinite loading #467

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

You must be logged in to vote

You can create a timeout yourself. Roughly:

import { createClient } from 'graphql-ws';

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

let timeout;
const dispose = client.subscribe(
  {
    query: '{ slowQuery }',
  },
  {
    next: (value) => {
      // value received, clear timeout
      clearTimeout(timeout);
    },
    error: (err) => {},
    complete: () => {},
  },
);
// remove subscription after a timeout of 3 seconds
timeout = setTimeout(dispose, 3000);

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@acuevas91
Comment options

@enisdenjo
Comment options

@acuevas91
Comment options

@enisdenjo
Comment options

@acuevas91
Comment options

Answer selected by acuevas91
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