diff --git a/lib/apollo.js b/lib/apollo.js index c3b7a6f5..1d127792 100644 --- a/lib/apollo.js +++ b/lib/apollo.js @@ -1,8 +1,8 @@ -import { ApolloClient, InMemoryCache, HttpLink, makeVar, split } from '@apollo/client' +import { ApolloClient, InMemoryCache, HttpLink, makeVar, split, from } from '@apollo/client' import { BatchHttpLink } from '@apollo/client/link/batch-http' import { decodeCursor, LIMIT } from './cursor' import { COMMENTS_LIMIT, SSR } from './constants' - +import { RetryLink } from '@apollo/client/link/retry' function isFirstPage (cursor, existingThings, limit = LIMIT) { if (cursor) { const decursor = decodeCursor(cursor) @@ -28,13 +28,30 @@ export default function getApolloClient () { export const meAnonSats = {} +const retryLink = new RetryLink({ + delay: { + initial: 300, + max: 30000, + jitter: true + }, + attempts: { + max: Infinity, + retryIf: (error, _operation) => { + return !!error + } + } +}) + function getClient (uri) { - const link = split( - // batch zaps if wallet is enabled so they can be executed serially in a single request - operation => operation.operationName === 'act' && operation.variables.act === 'TIP' && operation.getContext().batch, - new BatchHttpLink({ uri, batchInterval: 1000, batchDebounce: true, batchMax: 0, batchKey: op => op.variables.id }), - new HttpLink({ uri }) - ) + const link = from([ + retryLink, + split( + // batch zaps if wallet is enabled so they can be executed serially in a single request + operation => operation.operationName === 'act' && operation.variables.act === 'TIP' && operation.getContext().batch, + new BatchHttpLink({ uri, batchInterval: 1000, batchDebounce: true, batchMax: 0, batchKey: op => op.variables.id }), + new HttpLink({ uri }) + ) + ]) return new ApolloClient({ link,