Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@urql/exchange-retry

Package Overview
Dependencies
Maintainers
19
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@urql/exchange-retry

An exchange for operation retry support in urql

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
848K
decreased by-0.88%
Maintainers
19
Weekly downloads
 
Created

What is @urql/exchange-retry?

@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.

What are @urql/exchange-retry's main functionalities?

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],
});

Other packages similar to @urql/exchange-retry

Keywords

FAQs

Package last updated on 10 May 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc