阿波罗客户端,订阅片段
我正在尝试使用cache.ReadFragment
读取从缓存中读取,并订阅更改,就像useQuery
die一样。我尝试使用usequery
与fetchpolicy:'仅缓存'
,但是尽管我在缓存中看到我的实体,但数据却返回为null。 cache.ReadFragment
工作正常,但不订阅,这意味着将其应用于缓存的任何更改都不会重新触发它。
我如何实现这种行为,并在某些东西变为缓存后立即起作用?
// one time read
const data = client.cache.readFragment({
id: client.cache.identify({
__typename: 'Creator',
id: creatorId,
}),
fragment: IS_FOLLOWING_FRAGMENT,
}) as MyCreatorIsFollowing;
// comes back as null although I see it in the cache
const { data } = useQuery(GET_IS_FOLLOW_CREATOR, {
fetchPolicy: 'cache-only',
variables: { id: creatorId },
});
I am trying to read from the cache, using cache.readFragment
and subscribe to the changes just as useQuery
does. I tried using useQuery
with a fetchPolicy: 'cache-only'
but although I see my entity in the cache, the data comes back as null. The cache.readFragment
works fine, but it doesn't subscribe, meaning any change applied to the cache won't re-trigger it.
How can I implement that kind of behavior, and have it work right after something is mutated to the cache?
// one time read
const data = client.cache.readFragment({
id: client.cache.identify({
__typename: 'Creator',
id: creatorId,
}),
fragment: IS_FOLLOWING_FRAGMENT,
}) as MyCreatorIsFollowing;
// comes back as null although I see it in the cache
const { data } = useQuery(GET_IS_FOLLOW_CREATOR, {
fetchPolicy: 'cache-only',
variables: { id: creatorId },
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论