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

@urql/exchange-request-policy

Package Overview
Dependencies
Maintainers
6
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@urql/exchange-request-policy

An exchange for operation request-policy upgrading in urql

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13K
decreased by-17.44%
Maintainers
6
Weekly downloads
 
Created
Source

@urql/exchange-request-policy (Exchange factory)

@urql/exchange-request-policy is an exchange for the urql GraphQL client that will automatically upgrade operation request-policies on a time-to-live basis.

Quick Start Guide

First install @urql/exchange-request-policy alongside urql:

yarn add @urql/exchange-request-policy
# or
npm install --save @urql/exchange-request-policy

Then add it to your client.

import { createClient, cacheExchange, fetchExchange } from 'urql';
import { requestPolicyExchange } from '@urql/exchange-request-policy';

const client = createClient({
  url: 'http://localhost:1234/graphql',
  exchanges: [
    requestPolicyExchange({
      // The amount of time in ms that has to go by before upgrading, default is 5 minutes.
      ttl: 60 * 1000, // 1 minute.
      // An optional function that allows you to specify whether an operation should be upgraded.
      shouldUpgrade: operation => operation.context.requestPolicy !== 'cache-only',
    }),
    cacheExchange,
    fetchExchange,
  ],
});

Now when the exchange sees a cache-first operation that hasn't been seen in ttl amount of time it will upgrade the requestPolicy to cache-and-network.

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