如果我以下列形式获得该值,我怎么能得到查询返回的值:
await weekDates.map(datee =>
this.props.client.query({
query:queryFetchAppEventsByDate,
name:'fetchAppEvents',
variables:{
incubatorId: this.currentUser.incubator._id,
userId: this.props.getCurrentUser.currentUser._id,
date:datee
}
})
);
答案 0 :(得分:0)
如果您有一组promise,则必须使用Promise.all来获取结果或执行for循环并使用await
。
以下内容应该有效
Promise.all(
weekDates.map(date =>
this.props.client.query({//assuming query returns a promise
query: queryFetchAppEventsByDate,
name: 'fetchAppEvents',
variables: {
incubatorId: this.currentUser.incubator._id,
userId: this.props.getCurrentUser.currentUser._id,
date: date
}
})
)
).then(
results=>console.log("results:",results)
).catch(
error=console.log("something went wrong:",error)
);