パッケージの詳細

@urql/exchange-request-policy

urql-graphql86.7kMIT1.2.1

An exchange for operation request-policy upgrading in urql

urql, graphql client, graphql, exchanges

readme

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

更新履歴

Changelog

1.2.1

Patch Changes

  • Omit minified files and sourcemaps' sourcesContent in published packages Submitted by @kitten (See #3755)
  • Updated dependencies (See #3755)
    • @urql/core@5.1.1

1.2.0

Minor Changes

  • Mark @urql/core as a peer dependency as well as a regular dependency Submitted by @kitten (See #3579)

1.1.0

Minor Changes

  • Change the request-policy exchange not to rely on OperationMeta set by the cache exchanges Submitted by @JoviDeCroock (See #3521)

1.0.2

Patch Changes

  • Publish with npm provenance Submitted by @kitten (See #3180)

1.0.1

Patch Changes

1.0.0

Major Changes

  • Goodbye IE11! 👋 This major release removes support for IE11. All code that is shipped will be transpiled much less and will not be ES5-compatible anymore, by @kitten (See #2504)
  • Upgrade to Wonka v6 (wonka@^6.0.0), which has no breaking changes but is built to target ES2015 and comes with other minor improvements. The library has fully been migrated to TypeScript which will hopefully help with making contributions easier!, by @kitten (See #2504)

Patch Changes

0.1.5

Patch Changes

  • Extend peer dependency range of graphql to include ^16.0.0. As always when upgrading across many packages of urql, especially including @urql/core we recommend you to deduplicate dependencies after upgrading, using npm dedupe or npx yarn-deduplicate, by @kitten (See #2133)
  • Updated dependencies (See #2133)
    • @urql/core@2.3.6

0.1.4

Patch Changes

  • Do not set the TTL unless cache outcome is "miss". Previously we set the TTL on cache "miss" if it was the first time an operation returned a result, now the TTL is only set on cache miss results. This allows the request policy exchange to work when using persisted caching, by @Mookiies (See #1742)
  • Updated dependencies (See #1776 and #1755)
    • @urql/core@2.1.5

0.1.3

Patch Changes

  • ⚠️ Fix TTL being updated to a newer timestamp when a cached result comes in, and prevent TTL from being deleted on our React binding's cache probes. Instead we now never delete the TTL and update it on incoming cache miss results, by @kitten (See #1641)
  • Updated dependencies (See #1634 and #1638)
    • @urql/core@2.1.2

0.1.2

Patch Changes

  • Remove closure-compiler from the build step (See #1570)
  • Updated dependencies (See #1570, #1509, #1600, and #1515)
    • @urql/core@2.1.0

0.1.1

Patch Changes

  • ⚠️ Fix non-query operations being upgraded by requestPolicyExchange and time being stored by last issuance rather than last result, by @kitten (See #1377)
  • Updated dependencies (See #1374, #1357, and #1375)
    • @urql/core@2.0.0

v0.1.0

Initial Release