
Security News
Node.js TSC Votes to Stop Distributing Corepack
Corepack will be phased out from future Node.js releases following a TSC vote.
apollo-link-retry
Advanced tools
Sometimes, you're in an unreliable situation but you would rather wait longer than explicitly fail an operation. apollo-link-retry
provides exponential backoff, and jitters delays between attempts by default. It does not (currently) handle retries for GraphQL errors in the response, only for network errors.
One such use case is to hold on to a request while a network connection is offline and retry until it comes back online.
import { RetryLink } from "apollo-link-retry";
const link = new RetryLink();
The standard retry strategy provides exponential backoff with jittering, and takes the following options, grouped into delay
and attempt
strategies:
delay.initial
: The number of milliseconds to wait before attempting the first retry.
delay.max
: The maximum number of milliseconds that the link should wait for any retry.
delay.jitter
: Whether delays between attempts should be randomized.
attempts.max
: The max number of times to try a single operation before giving up.
attempts.retryIf
: A predicate function that can determine whether a particular response should be retried.
The default configuration is equivalent to:
new RetryLink({
delay: {
initial: 300,
max: Infinity,
jitter: true
},
attempts: {
max: 5,
retryIf: (error, _operation) => !!error
}
});
Starting with initialDelay
, the delay of each subsequent retry is increased exponentially, meaning it's multiplied by 2 each time. For example, if initialDelay
is 100, additional retries will occur after delays of 200, 400, 800, etc.
With the jitter
option enabled, delays are randomized anywhere between 0ms (instant), and 2x the configured delay. This way you get the same result on average, but with random delays.
These two features combined help alleviate the thundering herd problem, by distributing load during major outages. Without these strategies, when your server comes back up it will be hit by all of your clients at once, possibly causing it to go down again.
Instead of the options object, you may pass a function for delay
and/or attempts
, which implement custom strategies for each. In both cases the function is given the same arguments (count
, operation
, error
).
The attempts
function should return 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.
import { RetryLink } from "apollo-link-retry";
const link = new RetryLink({
attempts: (count, operation, error) => {
return !!error && operation.operationName != 'specialCase';
},
delay: (count, operation, error) => {
return count * 1000 * Math.random();
},
});
FAQs
Retry Apollo Link for GraphQL Network Stack
The npm package apollo-link-retry receives a total of 69,967 weekly downloads. As such, apollo-link-retry popularity was classified as popular.
We found that apollo-link-retry demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.
Research
Security News
Research uncovers Black Basta's plans to exploit package registries for ransomware delivery alongside evidence of similar attacks already targeting open source ecosystems.
Security News
Oxlint's beta release introduces 500+ built-in linting rules while delivering twice the speed of previous versions, with future support planned for custom plugins and improved IDE integration.