繁体   English   中英

有没有办法将复杂的 where 条件定义为变量?

[英]Is there a way define complex where conditions as variables?

我创建了一个 GraphQL 查询,它的条件变得复杂,但在 Apollo GraphQL iOS 客户端中,编译项目后无法更改查询。 Apollo GraphQL iOS 客户端提供了更改查询中定义的变量而不是查询本身的机会。

我原来的 Lighthouse GraphQL 查询如下所示;

query ($first:Int, $page:Int) {
    my_listings(
        where: {
            AND: [
                { column: NET_AREA, operator: GTE, value: 200 }
            ]
        }
        orderBy: [
            { column: ID, order: ASC }
            ]
        first: $first
        page: $page
    ) {
        data {
            ...listingFields
        }
        paginatorInfo {
            currentPage
            lastPage
        }
    }
}

Altered Lighthouse GraphQL 查询是这样的,只添加了MyListingsWhereWhereConditions类型的 $conditions 变量。

query($first: Int, $page: Int, $conditions:MyListingsWhereWhereConditions) {
  my_listings(
    where: $conditions
    orderBy: [{ column: ID, order: ASC }]
    first: $first
    page: $page
  ) {
    data {
      ...listingFields
    }
    paginatorInfo {
      currentPage
      lastPage
    }
  }
}

当我将以下变量提供给第二个查询时,Lighthouse 服务器返回以下消息

{
  "first": 1,
  "page": 1,
  "conditions": {"AND": {"column": "PRICE", "operator": "LTE","value": "190"}}
}

错误信息

Variable \"$conditions\" got invalid value {\"AND\":{\"column\":\"PRICE\",\"operator\":\"LTE\",\"value\":\"190\"}}; Expected type MyListingsWhereWhereConditions to be an object at value.AND.column.

有没有办法在变量中给出这些条件? 没有它,我无法找到一种在 iOS 客户端上更改 where 条件的方法。

“AND”应该包含对象数组,而不是对象。

"conditions": {"AND": [{"column": "PRICE", "operator": "LTE","value": "190"}}]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM