Her*_*778 4 reactjs graphql-js apollo-client
这是我的代码
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
}
}
`;
Run Code Online (Sandbox Code Playgroud)
当我提出请求时,我收到警告
替换 Query 对象的 my 字段时,缓存数据可能会丢失。
为了解决这个问题(这不是 Apollo Client 中的错误),要么确保所有 My 类型的 >objects 都有 ID,或者为 Query.my >field 定义一个自定义合并函数,这样 InMemoryCache 可以安全地合并这些现有的对象:
{"__typename":"My","getUser{"__typename":"User","email":"shakizriker0022@gmail.com"}}
incoming: {"__typename":"My","sendNewTokenForConfirmation":"SUCCESS"}
Run Code Online (Sandbox Code Playgroud)
有关这些选项的更多信息,请参阅文档:
我跟着链接。
我阅读了文档并意识到问题出在 apollo 客户端缓存(typePolicies)中。
但是我应该如何解决这个问题,我只是想不通。
我应该在 typePolicies 中写什么来摆脱警告?
您可能需要为 Apollo 返回一个 id 以在缓存中唯一标识该对象。我认为这个问题与您的类似: 链接
const CONFIRMATION_CODE = gql`
query {
my {
id
sendNewTokenForConfirmation
}
}
`;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7430 次 |
| 最近记录: |