这是我的代码
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
}
}
`;
当我提出请求时,我收到警告
替换 Query 对象的 my 字段时,缓存数据可能会丢失。
要解决这个问题(这不是 Apollo Client 中的错误),要么确保所有 My 类型的对象都有 ID,要么为 Query.my > 字段定义自定义合并函数,以便 InMemoryCache 可以安全地合并这些对象
现存的:
{"__typename":"My","getUser{"__typename":"User","email":"[email protected] /cdn-cgi/l/email-protection"}}
incoming: {"__typename":"My","sendNewTokenForConfirmation":"SUCCESS"}
有关这些选项的更多信息,请参阅文档:
我点击了链接。
我阅读了文档并意识到问题出在 apollo 客户端缓存(typePolicies)中。
但我应该如何解决这个问题我就是不知道。
我应该在 typePolicies 中写什么来消除警告?