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

时间:2018-04-27 04:47:39

标签: javascript graphql apollo graphql-js apollo-client

如果我以下列形式获得该值,我怎么能得到查询返回的值:

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

  );

1 个答案:

答案 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)
);