Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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