Last active
November 17, 2018 20:52
-
-
Save kamilkisiela/3579939c534d5f8ac001a98343a7442f 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