使用直接缓存访问时在地图中获取查询值

getting a query value inside a map when using direct cache access

如果我有以下形式的查询返回值,我该如何获取它:

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
     }
   })

  );

如果您有一系列承诺,则必须使用 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)
);