【问题标题】:GraphQL query that excludes results where an array relationship is empty排除数组关系为空的结果的 GraphQL 查询
【发布时间】:2021-10-20 21:03:25
【问题描述】:

我有这个问题(在 Hasura 中以防万一):

query MyQuery {
  records(distinct_on:[recordId],   where: { modelId: {_eq: "2f1f70b8-cb7b-487c-9e4c-ca03624ce926"}}) {
    recordId
    inboundEdges(where: {fromModelId: {_eq: "f0e19461-6d38-4148-8041-54eba6451293"}}) {
      fromRecord {
        property_path_values(where:{stringValue:{_eq:"2021-08-26"}}) {
          stringValue
        }
      }
    }
  }
}

我得到了这个结果:

{
  "data": {
    "records": [
      {
        "recordId": "2fbe37b1-78db-4b22-b713-2388cfb52597",
        "inboundEdges": [
          {
            "fromRecord": {
              "property_path_values": [
                {
                  "stringValue": "2021-08-26"
                }
              ]
            }
          },
          {
            "fromRecord": {
              "property_path_values": [
                {
                  "stringValue": "2021-08-26"
                },
                {
                  "stringValue": "2021-08-26"
                }
              ]
            }
          }
        ]
      },
      {
        "recordId": "7b34e85d-f4e1-4099-89d9-02483128a6cd",
        "inboundEdges": [
          {
            "fromRecord": {
              "property_path_values": [
                {
                  "stringValue": "2021-08-26"
                }
              ]
            }
          }
        ]
      },
      {
        "recordId": "840f52e2-0f2e-4591-810d-19f9e8840a49",
        "inboundEdges": []
      }
    ]
  }
}

我不希望响应中的第三个结果,因为它的 inboundEdges 数组是空的。

我想说的是:找到所有records 至少有一个inboundEdge 和一个fromRecord 至少有一个property_path_value 和一个stringValue 等于2021-08-26。我不想用inboundEdges === []解析需要排除结果的响应

【问题讨论】:

    标签: graphql hasura


    【解决方案1】:

    似乎我将选择集与陈述查询的位置混淆了。做我想做的事情的正确方法是:

    query MyQuery {
      records(where: {inboundEdges: {fromModelId: {_eq: "f0e19461-6d38-4148-8041-54eba6451293"}, fromRecord: {propertyPathValues: {stringValue: {_eq: "2021-08-26"}}}}, modelId: {_eq: "2f1f70b8-cb7b-487c-9e4c-ca03624ce926"}}) {
        recordId
      }
    }
    
    

    即将查询放在 where 子句中,就像普通人一样,而不是选择集

    【讨论】:

      猜你喜欢
      • 2023-03-06
      • 1970-01-01
      • 2022-01-26
      • 2018-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-14
      • 2019-07-07
      相关资源
      最近更新 更多