1.0.0-beta.2 • Published 7 years ago

apollo-angular-cache-ngrx v1.0.0-beta.2

Weekly downloads
872
License
MIT
Repository
github
Last release
7 years ago

NGRX Cache

npm version Get on Slack

Purpose

Allows to use @ngrx/store as Apollo Cache

Installation

npm install apollo-angular-cache-ngrx --save

Usage

Put apolloReducer under apollo in your State and simply import NgrxCacheModule.

import {StoreModule} from '@ngrx/store';
import {
  NgrxCacheModule,
  NgrxCache,
  apolloReducer,
} from 'apollo-angular-cache-ngrx';

@NgModule({
  imports: [
    StoreModule.forRoot({
      apollo: apolloReducer,
    }),
    NgrxCacheModule,
  ],
})
class AppModule {
  constructor(ngrxCache: NgrxCache) {
    const cache = ngrxCache.create({});
  }
}

Second method is about putting apolloReducer under any key you want to in your State and because of that, use NgrxCacheModule.forRoot(key: string) in imports, where key points to that key.

import {StoreModule} from '@ngrx/store';
import {
  NgrxCacheModule,
  NgrxCache,
  apolloReducer,
} from 'apollo-angular-cache-ngrx';

@NgModule({
  imports: [
    StoreModule.forRoot({
      myCustomApollo: apolloReducer,
    }),
    NgrxCacheModule.forRoot('myCustomApollo'),
  ],
})
class AppModule {
  constructor(ngrxCache: NgrxCache) {
    const cache = ngrxCache.create({});
  }
}

Options

Same options as in apollo-cache-inmemory.