问题描述
我是 GraphQL 的新手并做出反应,并试图弄清楚如何在 for 循环内调用 graphQl 请求(循环遍历 obj 列表)。这是一个反应项目。
目前,我的代码如下所示:
if(serviceLoadingQueryReq == false && serviceDataQueryReq != undefined)
{
let full = []
let new_service = {}
for (let ind = 0; ind < 50; ind++) {
const { data:contactInfo,loading:contactLoading,error: contactError } =
useGetQuery({
variables: {
input: 10
},});
}}
我什至尝试将查询调用带入子函数,但仍然遇到相同的错误。 我怀疑我的错误与这篇文章中的错误相似,但即使更改后,我仍然收到此错误。 chaining query trees w/o "Rendered more hooks than during the previous render"
子函数
const tester = () => {
const { data:contactInfo,error: contactError } = useGetServiceQuery({
variables: {
input: 10
},});
return 'ffsdfdsfsd'
}
父组件(带for循环)
if(serviceLoadingQueryReq == false && serviceDataQueryReq != undefined)
{
let full = []
let new_service = {}
for (let ind = 0; ind < 50; ind++) {
let temp = tester()
}
}
我目前正在使用 for 循环遍历类似于此 [ {id: 2},{id: 4} ...] 的对象列表。 在每个循环中,我想进行 graphql 查询调用以传入 id 以获取与该 id 关联的人的姓名。我通过在 for 循环中嵌套 gql 查询调用来做到这一点。并添加到对象中,使其成为像这样的对象列表:[ {id: 2,name: 'kevin'},{id: 4,name: 'bob'} ...] 在此过程中,我收到下图中的错误。您知道我如何解决此错误或调整我的方法吗?非常感谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)