我正在开发一个基于GraphQL/Apollo/Reaction的网络. 所以我想使用Mutation来发出POST请求,当完成时,我清理了一些针对某些查询的缓存.我读了Apollo的doc,它指导我如何从缓存和写操作中读取数据. 但我有三个问题:
- 我可以用一个客户端.ReadQuery调用读取多个查询缓存吗?如果答案是否定的,那么ReQuery是否同步执行?
- 如何在读取后清除查询缓存(而不是更新)?
- 查询的缓存更新或重新获取(Refetch In UseMutation)是否会强制重新呈现调用该查询的所有组件?
我的样例代码如下:
import type {DataProxy, FetchResult} from 'react-apollo'
import {useMutation} from '@apollo/react-hooks'
const[theMutationQuery] = useMutation(MUTATIONQUERY, {
refetchQueries: [somequery expression] // will the force a rerender of all components that use 'somequery'
onCompleted: () => {},
onError: () => {},
update: (store: DataProxy, data: FetchResult<?*>) => {
const cacheDataForOtherQuery = store.readQuery({
query: GETQUERY1
variables: {
v: "str",
},
// so can i add one more query here?
})
// then how should I clean up the result from readquery, that is, cacheDataForQuery. Also, after cleaning up, will this force a rerender of all components using the query(GETQUERY1 here)
}
});