Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sysgears/apollo-cache-router
Apollo GraphQL Cache Router
https://github.com/sysgears/apollo-cache-router
apollo apollo-client graphql
Last synced: 4 days ago
JSON representation
Apollo GraphQL Cache Router
- Host: GitHub
- URL: https://github.com/sysgears/apollo-cache-router
- Owner: sysgears
- License: mit
- Created: 2018-04-16T07:38:17.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-14T09:28:33.000Z (about 6 years ago)
- Last Synced: 2024-04-24T01:02:03.657Z (7 months ago)
- Topics: apollo, apollo-client, graphql
- Language: TypeScript
- Homepage:
- Size: 30.3 KB
- Stars: 7
- Watchers: 17
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Apollo Cache Router
[![npm version](https://badge.fury.io/js/apollo-cache-router.svg)](https://badge.fury.io/js/apollo-cache-router)
[![Twitter Follow](https://img.shields.io/twitter/follow/sysgears.svg?style=social)](https://twitter.com/sysgears)## Installation
```bash
npm install --save-dev apollo-cache-router
```## Usage
``` js
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 => {
const operationName = getOperationAST(document).name;
if (hasDirectives(['client'], document)
|| (operationName && operationName.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`](https://github.com/sysgears/apollo-cache-logger)## License
Copyright © 2018 [SysGears LTD]. This source code is licensed under the [MIT] license.[MIT]: LICENSE
[SysGears LTD]: http://sysgears.com