
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@urql/exchange-retry
Advanced tools
@urql/exchange-retry is an npm package that provides retry logic for GraphQL requests made using the urql client. It allows developers to specify retry strategies for failed requests, improving the resilience and reliability of their applications.
Basic Retry Logic
This feature allows you to add basic retry logic to your urql client. The retryExchange is added to the list of exchanges, enabling automatic retries for failed requests.
const { retryExchange } = require('@urql/exchange-retry');
const { createClient, dedupExchange, cacheExchange, fetchExchange } = require('urql');
const client = createClient({
url: 'https://my-graphql-endpoint.com/graphql',
exchanges: [dedupExchange, cacheExchange, retryExchange(), fetchExchange],
});
Custom Retry Logic
This feature allows you to customize the retry logic by specifying parameters such as initial delay, maximum delay, random delay, maximum number of attempts, and conditions for retrying.
const { retryExchange } = require('@urql/exchange-retry');
const { createClient, dedupExchange, cacheExchange, fetchExchange } = require('urql');
const retryConfig = {
initialDelayMs: 1000,
maxDelayMs: 15000,
randomDelay: true,
maxNumberAttempts: 5,
retryIf: (error) => error.networkError,
};
const client = createClient({
url: 'https://my-graphql-endpoint.com/graphql',
exchanges: [dedupExchange, cacheExchange, retryExchange(retryConfig), fetchExchange],
});
Exponential Backoff
This feature allows you to implement exponential backoff for retries. The backoff function calculates the delay before the next retry attempt, increasing exponentially with each attempt.
const { retryExchange } = require('@urql/exchange-retry');
const { createClient, dedupExchange, cacheExchange, fetchExchange } = require('urql');
const retryConfig = {
initialDelayMs: 500,
maxDelayMs: 10000,
randomDelay: true,
maxNumberAttempts: 3,
retryIf: (error) => error.networkError,
backoff: (attempt) => Math.min(1000 * 2 ** attempt, 30000),
};
const client = createClient({
url: 'https://my-graphql-endpoint.com/graphql',
exchanges: [dedupExchange, cacheExchange, retryExchange(retryConfig), fetchExchange],
});
axios-retry is a library that adds retry functionality to axios, a popular HTTP client. It allows you to specify retry strategies for failed HTTP requests. Compared to @urql/exchange-retry, axios-retry is more general-purpose and can be used with any HTTP requests, not just GraphQL.
fetch-retry is a library that adds retry logic to the Fetch API. It allows you to specify retry strategies for failed fetch requests. Similar to axios-retry, fetch-retry is more general-purpose and can be used with any HTTP requests, whereas @urql/exchange-retry is specifically designed for urql and GraphQL.
@urql/exchange-retry
is an exchange for the urql
GraphQL client that allows operations (queries, mutations, subscriptions) to be retried based on an options
parameter.
First install @urql/exchange-retry
alongside urql
:
yarn add @urql/exchange-retry
# or
npm install --save @urql/exchange-retry
Read more about the retry exchange.
FAQs
An exchange for operation retry support in urql
The npm package @urql/exchange-retry receives a total of 697,767 weekly downloads. As such, @urql/exchange-retry popularity was classified as popular.
We found that @urql/exchange-retry demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 19 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
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.