gpt4 book ai didi

reactjs - 替换 Query 对象的 my 字段时缓存数据可能会丢失

转载 作者:行者123 更新时间:2023-12-03 23:34:06 25 4
gpt4 key购买 nike

这是我的代码

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
}
}
`;
当我提出请求时,我收到警告

Cache data may be lost when replacing the my field of a Query object.

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 objectsexisting:

    {"__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:


我跟着链接。
我阅读了文档并意识到问题出在 apollo 客户端缓存(typePolicies)中。
但是我应该如何解决这个问题,我只是想不通。
我应该在 typePolicies 中写什么来摆脱警告?

最佳答案

您可能需要为 Apollo 返回一个 id 以在缓存中唯一标识该对象。
我认为这个问题与您的相似:
link

const CONFIRMATION_CODE = gql`
query {
my {
id
sendNewTokenForConfirmation
}
}
`;

关于reactjs - 替换 Query 对象的 my 字段时缓存数据可能会丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63423578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com