如何使用reactjs @apollo/client v3获取所有缓存数据
How to get all cache data using reactjs @apollo/client v3
我是否可以检查所有缓存,例如:apollo 中的更改以进行调试。
像 redux store 之类的东西,你可以在其中查看整个状态树。
他们提到:
The cache stores the objects by ID in a flat lookup table.
https://www.apollographql.com/docs/react/caching/cache-configuration/
有什么方法可以 display/console 整个查找 table?
对于@apollo/client v3
找到答案,如果有人感兴趣的话。
- 通过
InMemoryCache
您可以控制台记录您使用 InMemoryCache 创建的缓存对象。
您应该能够在您创建的缓存下找到它:
const cache = new InMemoryCache({"...Your option"})
console.log(cache.data) // <- Your cache query
- 通过
browser console
通过浏览器,使用控制台登录data
__APOLLO_CLIENT__.cache.data
- 通过
apollo
v3
通过apollo客户端缓存访问
const client = useApolloClient();
const serializedState = client.cache.extract();
console.log(serializedState) <- your cache query
我是否可以检查所有缓存,例如:apollo 中的更改以进行调试。 像 redux store 之类的东西,你可以在其中查看整个状态树。
他们提到:
The cache stores the objects by ID in a flat lookup table. https://www.apollographql.com/docs/react/caching/cache-configuration/
有什么方法可以 display/console 整个查找 table?
对于@apollo/client v3
找到答案,如果有人感兴趣的话。
- 通过
InMemoryCache
您可以控制台记录您使用 InMemoryCache 创建的缓存对象。 您应该能够在您创建的缓存下找到它:
const cache = new InMemoryCache({"...Your option"})
console.log(cache.data) // <- Your cache query
- 通过
browser console
通过浏览器,使用控制台登录data
__APOLLO_CLIENT__.cache.data
- 通过
apollo
v3
通过apollo客户端缓存访问
const client = useApolloClient();
const serializedState = client.cache.extract();
console.log(serializedState) <- your cache query