apollo-cache-router
TypeScript icon, indicating that this package has built-in type declarations

1.1.6 • Public • Published

Apollo Cache Router

npm version Twitter Follow

Installation

npm install --save-dev apollo-cache-router

Usage

import { InMemoryCache } from 'apollo-cache-inmemory';
import ApolloCacheRouter from 'apollo-cache-router';
import { hasDirectives } from 'apollo-utilities';
 
const netCache = new InMemoryCache();
const localCache = new InMemoryCache();
const cache = ApolloCacheRouter.override(
  ApolloCacheRouter.route([netCache, localCache], document => {
    if (hasDirectives(['client'], document)
        || getOperationAST(document).name.value === 'GeneratedClientQuery') {
      // Pass all @client queries and @client defaults to localCache
      return [localCache];
    } else {
      // Pass all the other queries to netCache
      return [netCache];
    }
  }),
  {
    reset: () => {
      // On apolloClient.resetStore() reset only netCache and keep localCache intact
      return netCache.reset();
    }
  }
);

Logging

If you want log cache access and errors please check apollo-cache-logger

License

Copyright © 2018 SysGears LTD. This source code is licensed under the MIT license.

Readme

Keywords

Package Sidebar

Install

npm i apollo-cache-router

Weekly Downloads

114

Version

1.1.6

License

MIT

Unpacked Size

53.5 kB

Total Files

9

Last publish

Collaborators

  • vicvlas