执行查询之后,懒惰查询GraphQl响应数据在React内部无法访问
按下下载按钮时,我需要调用查询,然后处理响应。我只需要在按下下载按钮时即可执行查询,而不是当React组件加载时。因此,我从GraphQl使用了“ Uselazyquery”选项。
我需要这样的东西:
const [downloadAllRecipients,{ loading, error, data }] = useLazyQuery(QUERY,
{
variables: {
campaignId: props.campaignId,
},
fetchPolicy: 'network-only',
},
);
//This is the download button onPress event handler.
const downloadDataButton = async () => {
const res = await downloadAllRecipients({ variables: { campaignID: props.campaignId }})
console.log(res) // handle response
}
//Output:-
//undefined
执行上述查询时, res 是未定义的。但是,在网络层中可以看到GraphQl查询。我有一个React前端,无法访问查询返回的数据。请帮助! 提前致谢!
I need to call a query when Download button is pressed and then handle the response.I only need to execute the query when download button is pressed and not when the react component loads. Hence I used 'useLazyQuery' option from graphql.
I need something like this:
const [downloadAllRecipients,{ loading, error, data }] = useLazyQuery(QUERY,
{
variables: {
campaignId: props.campaignId,
},
fetchPolicy: 'network-only',
},
);
//This is the download button onPress event handler.
const downloadDataButton = async () => {
const res = await downloadAllRecipients({ variables: { campaignID: props.campaignId }})
console.log(res) // handle response
}
//Output:-
//undefined
When executing the above query, res is undefined. However, the graphql query was seen in the network layer. I have a react frontend and am not able to access the data returned by the query.Please help!
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将在
oncompleded
事件中获取数据。因此您的代码应该看起来像以下内容,
You will get the data in
onCompleted
event.So your code should look like following,