替换查询对象的my字段时,缓存数据可能会丢失 [英] Cache data may be lost when replacing the my field of a Query object
问题描述
这是我的代码
const NewVerificationCode = () => {
const { loading, error, data = {}, refetch } = useQuery(CONFIRMATION_CODE, {
skip: true,
onError: (err) => {},
});
console.log(loading, error, data);
if (loading || error) {
return <ErrorLoadingHandler {...{ loading, error }} />;
}
return (
<form
onSubmit={(e) => {
refetch();
e.preventDefault();
}}
>
<div>
<button type="submit" className="signUpbutton">
{"Send the message again"}
</button>
</div>
</form>
);
};
const CONFIRMATION_CODE = gql`
query {
my {
sendNewTokenForConfirmation
}
}
`;
我提出请求时会收到警告
when i make a request i get a warning
替换查询对象的my字段时,缓存数据可能会丢失.
Cache data may be lost when replacing the my field of a Query object.
要解决此问题(这不是Apollo Client中的错误),请确保My类型的所有>对象都具有ID,或者为Query.my>字段定义自定义合并功能,以便InMemoryCache可以安全地合并这些对象 现有:
To address this problem (which is not a bug in Apollo Client), either ensure all >objects of type My have IDs, or define a custom merge function for the Query.my >field, so InMemoryCache can safely merge these objects existing:
{"__typename":"My","getUser{"__typename":"User","email":"shakizriker0022@gmail.com"}}
incoming: {"__typename":"My","sendNewTokenForConfirmation":"SUCCESS"}
有关这些选项的更多信息,请参阅文档:
For more information about these options, please refer to the documentation:
我关注了链接.
我阅读了文档,并意识到问题出在阿波罗客户端缓存(typePolicies)中.
I read the documentation and realized that the problem is in the apollo client cache (typePolicies).
但是我怎么解决这个我不知道的问题.
But how should I solve this problem I just can't figure out.
我应该在typePolicies中写些什么来摆脱警告?.
What should i write in typePolicies to get rid of the warning ?.
推荐答案
您可能需要返回Apollo的ID,以在缓存中唯一标识该对象. 我认为这个问题与您的问题类似: 链接
You may need to return an id for Apollo to uniquely identify that object in the cache. I think this issue is similar to yours: link
const CONFIRMATION_CODE = gql`
query {
my {
id
sendNewTokenForConfirmation
}
}
`;
这篇关于替换查询对象的my字段时,缓存数据可能会丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!