在 GraphQL 中针对单列添加多个选项

Adding multiple options in against single column in GraphQL

我正在尝试进行查询,我可以在其中添加具有多个选项的过滤器。我目前有这个查询

query FacilitiesQuery(
    $limit: Int
    $offset: Int
    $query: String
    $sort: [facilities_order_by!]
  ) {
    facilities(
      limit: $limit
      offset: $offset
      where: {
        _or: [
          { name: { _ilike: $query } },
          { location: { _ilike: $query } },
        ]
        _and: [
          { deleted_at: { _is_null: true } },
          { status_id: { _eq: 1 } }
        ]
      }
      order_by: $sort
    ) {
      id
      location
      name
      status_id
      updated_at
      created_at
      area
      floor
      handover_condition
      handover_meter
      handover_office
      lcd
      level
      move_in_date
      rcd
      company_id
      deleted_at
      expiry_date
      area_type
      building_name
      enum_area_type {
        id
        name
      }
    }
    enum_facility_statuses {
      id
      value
    }
    facilities_aggregate(where: { deleted_at: { _is_null: true } }) {
      aggregate {
        count
      }
    }
  }

我正在尝试通过 status_id 进行查询。我正在尝试在前端实现一个过滤器,它可以基于带有复选框的模式获取所有选中的选项。

例如,我想用 status_id 1 和 2 获取记录,我正在寻找这样的东西

_and: [
  { deleted_at: { _is_null: true } },
  { status_id: { _eq: [1,2] } }
]

但我无法执行它们。我需要帮助以这种方式修改此查询。

在您的查询中,您需要指定正确的类型,由 Hasura 自动生成。在 Hasura 控制台的 GraphiQL 选项卡中,有一个文档资源管理器选项卡。在那里你可以看到 Hasura 为每个查询生成的类型。

您需要检查您的 Hasura 控制台,但您的查询应该类似于:

query FacilitiesQuery(
    $limit: Int
    $offset: Int
    $where: facilities_bool_exp!
    $sort: [facilities_order_by!]
  ) {
    facilities(
      limit: $limit
      offset: $offset
      where: $where
      }
      order_by: $sort
    ) {
      id
      location
      name
      status_id
      updated_at
      created_at
      area
      floor
      handover_condition
      handover_meter
      handover_office
      lcd
      level
      move_in_date
      rcd
      company_id
      deleted_at
      expiry_date
      area_type
      building_name
      enum_area_type {
        id
        name
      }
    }
    enum_facility_statuses {
      id
      value
    }
    facilities_aggregate(where: { deleted_at: { _is_null: true } }) {
      aggregate {
        count
      }
    }
  }

您可以根据需要构建位置。