1.1.6 • Published 7 years ago
apollo-cache-router v1.1.6
Apollo Cache Router
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.