-
-
Save danielsmeyer/5a53dc935e834d1dee9b8f09f2d9f588 to your computer and use it in GitHub Desktop.
Apollo Angular Ngrx Cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, /* ... */ }); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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