Skip to content

Instantly share code, notes, and snippets.

@kamilkisiela
Last active November 17, 2018 20:52
Show Gist options
  • Save kamilkisiela/3579939c534d5f8ac001a98343a7442f to your computer and use it in GitHub Desktop.
Save kamilkisiela/3579939c534d5f8ac001a98343a7442f to your computer and use it in GitHub Desktop.
Apollo Angular Ngrx Cache
import { NgrxCacheModule, NgrxCache } from 'apollo-cache-ngrx';
@NgModule({
imports: [
// ...
NgrxCacheModule.forFeature()
],
})
export class AppModule {
constructor(
apollo: Apollo,
ngrxCache: NgrxCache
) {
const cache = ngrxCache.create();
apollo.create({ cache, /* ... */ });
}
}
import { StoreModule } from '@ngrx/store';
import { NgrxCacheModule, NgrxCache, cacheReducer, CacheState } from 'apollo-cache-ngrx';
interface State {
apollo: CacheState;
}
const reducers = {
apollo: cacheReducer
};
const selector = (state: State) => state.apollo;
@NgModule({
imports: [
// ...
StoreModule.forRoot<State>(reducers),
NgrxCacheModule
],
})
export class AppModule {
constructor(
apollo: Apollo,
ngrxCache: NgrxCache
) {
const cache = ngrxCache.create({ selector })
apollo.create({ cache, /* ... */ });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment