@aotimme/urql-exchange-refetch-interval
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

@aotimme/urql-exchange-refetch-interval

@aotimme/urql-exchange-refetch-interval is an exchange for the urql GraphQL client that refetches queries on a specified interval.

Quick Start Guide

First install @aotimme/urql-exchange-refetch-interval alongside urql:

yarn add @aotimme/urql-exchange-refetch-interval
# or
npm install --save @aotimme/urql-exchange-refetch-interval

Then add it to your Client.

You will likely want to put it before the cacheExchange since that can filter out operations that you will want to refetch. And you will also want it before any asynchronous exchanges, like the fetchExchange.

import { createClient, cacheExchange, fetchExchange } from 'urql';
import { refetchIntervalExchange } from '@aotimme/urql-exchange-refetch-interval';

const client = createClient({
  url: 'http://localhost:3000/graphql',
  exchanges: [refetchIntervalExchange({refetchInterval: 30000}), cacheExchange, fetchExchange],
});

You can also specify the refetchInterval as a function taking in an urql Operation:

import { createClient, cacheExchange, fetchExchange } from 'urql';
import { refetchIntervalExchange } from '@aotimme/urql-exchange-refetch-interval';

const refetchInterval = (op) => {
  if (op.context.requestPolicy === "cache-only") {
    return false;
  }
  return 30000;
}

const client = createClient({
  url: 'http://localhost:3000/graphql',
  exchanges: [refetchIntervalExchange({refetchInterval}), cacheExchange, fetchExchange],
});

Package Sidebar

Install

npm i @aotimme/urql-exchange-refetch-interval

Weekly Downloads

36

Version

0.0.5

License

MIT

Unpacked Size

11.7 kB

Total Files

9

Last publish

Collaborators

  • aotimme