【问题标题】:How to efficiently use the result of a Hasura query for another query?如何有效地将 Hasura 查询的结果用于另一个查询?
【发布时间】:2020-09-22 15:48:11
【问题描述】:

我目前正在使用 userId 查询我的 Hasura 数据库以获取位置。

users(where: {id: {_eq: 1528}}) {
    location
}

然后我使用位置来查询该用户附近的用户。

    users(
      where:
        { location: {_st_d_within: {distance: 20000, from: $point }}},
    ) {
      firstName
      city
      region
    }
  }

有没有办法有效地组合这两个查询,以便我只查询一次?

【问题讨论】:

  • 您好,我有点困惑在同一个查询中使用多个过滤器有何帮助。我首先需要使用 id 1528 进行查询以获取位置。只有这样我才有位置过滤下一系列结果。
  • 嗯......你不能在一个查询中做到这一点

标签: postgresql graphql subquery hasura


【解决方案1】:

您不能将这两个查询合二为一。

您可以做的是创建一个 Postgres 函数并按照 Hasura 文档中的说明查询该函数:

https://hasura.io/docs/1.0/graphql/manual/schema/custom-functions.html#example-postgis-functions

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-02
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    相关资源
    最近更新 更多