-
-
Save danielsmeyer/a99a5f23d610f1f0185f1cf75956658f to your computer and use it in GitHub Desktop.
Apollo Angular Ngrx Cache
This file contains 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 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