有没有一种方法可以将复杂的条件定义为变量? [英] Is there a way define complex where conditions as variables?

查看:99
本文介绍了有没有一种方法可以将复杂的条件定义为变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个GraphQL查询,该查询在条件复杂的地方变得复杂,但是在Apollo GraphQL iOS客户端中,编译项目后无法更改查询.Apollo GraphQL iOS客户端使您有机会更改查询中的已定义变量,但不能更改查询本身.

I have created a GraphQL Query that gets complex where conditions but in Apollo GraphQL iOS client there is no way of changing query after compiling the project. Apollo GraphQL iOS client gives chance to change defined variables in the query but not the query itself.

我最初的Lighthouse GraphQL查询如下:

My original Lighthouse GraphQL query is like following;

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
        }
    }
}

更改后的Lighthouse GraphQL查询是这样的,仅添加了 MyListingsWhereWhereConditions 类型的$ conditions变量.

Altered Lighthouse GraphQL query is like this, only added $conditions variable which is MyListingsWhereWhereConditions type.

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服务器将向我返回以下消息

When I give the following variables into the second query Lighthouse server returns me the following message

{
  "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客户端条件的方法.

Is there a way of giving these conditions in a variable ? Without it I couldn't find a way of changing where condition on iOS client.

推荐答案

" AND"应该包含对象数组,而不是对象.

"AND" should contain array of objects, not object.

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

这篇关于有没有一种方法可以将复杂的条件定义为变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆