From 24379c1e46ce87aaa007b35529c80396d4d04af2 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sun, 21 Jan 2024 22:31:20 +0100 Subject: [PATCH] Infinitely try to reconnect gql subscriptions (#563) --- src/lib/requests/client/GraphQLClient.ts | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/lib/requests/client/GraphQLClient.ts b/src/lib/requests/client/GraphQLClient.ts index 62c3a6bd..1a60a56b 100644 --- a/src/lib/requests/client/GraphQLClient.ts +++ b/src/lib/requests/client/GraphQLClient.ts @@ -160,6 +160,32 @@ export class GraphQLClient extends BaseClient< this.wsClient = createClient({ url: () => this.getBaseUrl().replace(/http(|s)/g, 'ws'), keepAlive: 20000, + retryAttempts: Infinity, + retryWait: async (retries) => { + const getDelayInMS = () => { + if (retries < 10) { + return 1000 * 5; + } + + if (retries < 50) { + return 1000 * 10; + } + + if (retries < 500) { + return 1000 * 30; + } + + if (retries < 1000) { + return 1000 * 60; + } + + return 1000 * 60 * 5; + }; + + await new Promise((resolve) => { + setTimeout(resolve, getDelayInMS()); + }); + }, }); this.client = new ApolloClient({