【问题标题】:Use array as variable for GraphQL Query使用数组作为 GraphQL 查询的变量
【发布时间】:2019-07-29 10:05:29
【问题描述】:

我想查询多个变量的嵌套字段。 在这种情况下,我想查询 RPR,但仅在给定嵌套区域的标签时才返回 RPR。嵌套区域(字段:标签)的一个变量可以正常工作,但是如何过滤同一字段的多个变量

我的看法是,当我调用查询客户端(在我的情况下是通过 Apollo)时,我想将一个数组作为变量,让后端的查询通过该数组并返回基于数组中给定的任何变量。

然后解析器什么也不做:

rPRs: (root, args, ctx, info) => {
 return ctx.db.query.rPRs(args, info);
}

架构的相关部分:

    type RPR {
      id: ID! @Unique
      RPRID: String! @Unique
      state: String
      region: Region!
      resource: Resource!
      price: Float
      theme: String
      editionTitle: String
      information: String
    }

    type Region {
      id: ID! @Unique
      regionID: String! @Unique
      label: String! @Unique
      name: String! @Unique
      aov: Float!
      aov_multiplier: Float!
    }

检索所有带有嵌套区域的“RPR”的当前查询:


    query ADVICE_RESOURCES_QUERY($theme: String, $regio: String) {
      rPRs(where: {
        theme: $theme,
        region: {
          label: $regio
        }
      })
      {
        RPRID
        region {
          label
        }
      }
    }

【问题讨论】:

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


    【解决方案1】:

    您应该能够使用label_in 过滤器并向其提供字符串数组。您的 where 将如下所示:

    where: {
        theme: $theme,
        region: {
          label_in: $regio
        }
      }
    

    【讨论】:

      猜你喜欢
      • 2018-02-05
      • 2020-01-22
      • 2022-01-21
      • 2017-12-27
      • 2019-12-03
      • 2019-05-17
      • 2023-03-12
      • 2018-03-02
      • 2017-10-17
      相关资源
      最近更新 更多