Skip to content

Commit 8f201b5

Browse files
committed
Update retry link
1 parent 986a441 commit 8f201b5

1 file changed

Lines changed: 40 additions & 59 deletions

File tree

Lines changed: 40 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,19 @@
11
---
2-
title: Retry Link
2+
title: RetryLink
33
description: Attempt an operation multiple times if it fails due to network or server errors.
44
---
55

6-
## Overview
6+
<DocBlock
7+
canonicalReference="@apollo/client/link/retry!RetryLink:class"
8+
customOrder={["summary", "remarks", "example"]}
9+
/>
710

8-
`@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.
13-
14-
```js
15-
import { RetryLink } from "@apollo/client/link/retry";
16-
17-
const link = new RetryLink();
18-
```
19-
20-
## Options
21-
22-
The standard retry strategy provides exponential backoff with jittering, and takes the following options, grouped into `delay` and `attempt` strategies:
23-
24-
### options.delay
25-
26-
| Option | Description |
27-
| --------------- | --------------------------------------------------------------------------- |
28-
| `delay.initial` | The number of milliseconds to wait before attempting the first retry. |
29-
| `delay.max` | The maximum number of milliseconds that the link should wait for any retry. |
30-
| `delay.jitter` | Whether delays between attempts should be randomized. |
31-
32-
### options.attempts
33-
34-
| Option | Description |
35-
| ------------------ | ---------------------------------------------------------------------------------------- |
36-
| `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
4212

4313
```ts
44-
new RetryLink({
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
5517
```
5618

5719
## Avoiding thundering herd
@@ -68,15 +30,34 @@ Instead of the options object, you may pass a function for `delay` and/or `attem
6830

6931
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.
7032

71-
```js
72-
import { RetryLink } from "@apollo/client/link/retry";
73-
74-
const link = new RetryLink({
75-
attempts: (count, operation, error) => {
76-
return !!error && operation.operationName != "specialCase";
77-
},
78-
delay: (count, operation, error) => {
79-
return count * 1000 * Math.random();
80-
},
81-
});
82-
```
33+
## Types
34+
35+
<InterfaceDetails
36+
canonicalReference="@apollo/client/link/retry!DelayFunction:interface"
37+
headingLevel={3}
38+
displayName="DelayFunction"
39+
/>
40+
41+
<InterfaceDetails
42+
canonicalReference="@apollo/client/link/retry!RetryFunction:interface"
43+
headingLevel={3}
44+
displayName="RetryFunction"
45+
/>
46+
47+
<InterfaceDetails
48+
canonicalReference="@apollo/client/link/retry!RetryLink.Options:interface"
49+
headingLevel={3}
50+
displayName="RetryLink.Options"
51+
/>
52+
53+
<InterfaceDetails
54+
canonicalReference="@apollo/client/link/retry!DelayFunctionOptions:interface"
55+
headingLevel={3}
56+
displayName="DelayFunctionOptions"
57+
/>
58+
59+
<InterfaceDetails
60+
canonicalReference="@apollo/client/link/retry!RetryFunctionOptions:interface"
61+
headingLevel={3}
62+
displayName="RetryFunctionOptions"
63+
/>

0 commit comments

Comments
 (0)