【问题标题】:Graphql set where parameter of type array to optionalGraphql 将数组类型的 where 参数设置为可选
【发布时间】:2021-12-22 18:39:15
【问题描述】:

我有这个问题

query restrictionsTrav($match: String, $offset: Int, $stateIds: [Int!]) {
  destinations_for_travel(limit: 100, offset: $offset, where: {city_name: {name: {_ilike: $match}, province_name: {state_Name: {id: {_in: $stateIds}}}}}) {
    is_Travel_Allowed
    city_status {
      name
      status
    }
    city_name{
      name
      province_name{
        name
        key
        state_Name{
          name
          long_name
          key
        }
      }
    }
    updated_at
  }
}

基本上,当我在 Hasura 上查询它时,我有以下查询变量:matchoffsetstateIds。 我想要发生的是,即使我将 stateIds 留空,我仍然会看到与变量 match 表示的 city_name 匹配的结果。我尝试从stateIds 中删除!,但出现错误:

Variable "$stateIds" of type "[Int]" used in position expecting type "[Int!]"

有没有办法让stateIds 成为可选的?对于上面的查询,如果数组stateIds 中没有值,则不会显示任何内容。

【问题讨论】:

  • @xadm 不起作用。删除!在 Hasura 中也给了我一个错误
  • 阅读整个答案...将where 对象作为变量传递,而不是它的部分/片段

标签: graphql hasura


【解决方案1】:

要使其成为可选,您可以传递一个默认值,例如 $stateIds: [Int!] = []

【讨论】:

    猜你喜欢
    • 2020-08-25
    • 2014-09-14
    • 1970-01-01
    • 1970-01-01
    • 2022-08-05
    • 2017-12-16
    • 1970-01-01
    • 2018-08-15
    • 1970-01-01
    相关资源
    最近更新 更多