You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`@apollo/client/link/retry` can be used to retry an operation a certain amount of times. This comes in handy when dealing with unreliable communication situations, where you would rather wait longer than explicitly fail an operation. `@apollo/client/link/retry` provides exponential backoff, and jitters delays between attempts by default.
9
-
10
-
> **Note:** It does not currently handle retries for GraphQL errors in the response, only for network errors; the `onError` link can be used to retry an operation after a GraphQL error. For more information, see the [Error handling documentation](/react/data/error-handling/#on-graphql-errors).
11
-
12
-
An example use case is to hold on to a request while a network connection is offline, and retry until it comes back online.
The standard retry strategy provides exponential backoff with jittering, and takes the following options, grouped into `delay` and `attempt` strategies:
|`attempts.max`| The max number of times to try a single operation before giving up. |
37
-
|`attempts.retryIf`| A predicate function that can determine whether a particular response should be retried. |
38
-
39
-
### Default configuration
40
-
41
-
The default configuration is equivalent to:
11
+
## Constructor signature
42
12
43
13
```ts
44
-
newRetryLink({
45
-
delay: {
46
-
initial: 300,
47
-
max: Infinity,
48
-
jitter: true,
49
-
},
50
-
attempts: {
51
-
max: 5,
52
-
retryIf: (error, _operation) =>!!error,
53
-
},
54
-
});
14
+
constructor(
15
+
options?:RetryLink.Options
16
+
): RetryLink
55
17
```
56
18
57
19
## Avoiding thundering herd
@@ -68,15 +30,34 @@ Instead of the options object, you may pass a function for `delay` and/or `attem
68
30
69
31
The `attempts` function should return a `boolean` (or a `Promise` which resolves to a `boolean`) indicating whether the response should be retried. If yes, the `delay` function is then called, and should return the number of milliseconds to delay by.
0 commit comments