apollo-cache-persist
https://www.apollographql.com/docs/react/caching/cache-interaction/#cache-persistence
https://github.com/apollographql/apollo-cache-persist
Apolloでデータフェッチした結果を永続化するためのモジュール
2019年頭には動きがなく、Chromeの拡張ツールも結果がリアルタイムに反映されずに全然使えなそうに見えたが、最近動きが出始めた?
注意:2020-01-27 現在、使うとすべてのデータをキャッシュすることになる
client側でfetchPolicyを切り替えるとかで頑張る
code:初期化の例.tsx
import { persistCache } from 'apollo-cache-persist';
const cache = new InMemoryCache();
// await before instantiating ApolloClient, else queries might run before the cache is persisted
async function init() {
await persistCache({
cache,
storage: window.localStorage as any,
});
}
init();
const client = new ApolloClient({
cache,
// https://www.apollographql.com/docs/link/#apollo-client
link: createHttpLink({
uri: '/graphql',
}),
typeDefs,
resolvers,
});