【问题标题】:GraphQL parameters for an exists filter in API PlatformAPI 平台中存在过滤器的 GraphQL 参数
【发布时间】:2023-02-11 02:00:32
【问题描述】:

我为一个实体设置了一个存在过滤器:

#[ApiFilter(ExistsFilter::class, properties: ['firstName', 'lastName'])]

然后我可以很好地运行查询:

query accounts {
  accounts(exists: {firstName: true}) {
    edges {
      node {
        id
      }
    }
  }
}

但我想参数化 exists 过滤器。我得到的最接近的是:

询问

query getAccounts($exists: [AccountFilter_exists]) {
  accounts(exists: $exists) {
    edges {
      node {
        id
      }
    }
  }
}

参数

{
  "exists": {"firstName": true}
}

但我收到此错误消息:

{
  "errors": [
    {
      "message": "Variable \"$exists\" got invalid value {\"firstName\":true}; Expected type AccountFilter_exists to be an object at value.firstName.",
      "extensions": {
        "category": "graphql"
      },
      "locations": [
        {
          "line": 1,
          "column": 19
        }
      ]
    }
  ]
}

有谁知道我要去哪里错了?

感谢您的帮助。

【问题讨论】:

    标签: graphql api-platform.com


    【解决方案1】:

    您实际上需要以这种格式提供存在的过滤器:

    {
      "exists": [{"firstName": true}]
    }
    

    https://api-platform.com/docs/v2.7/core/graphql/#syntax-for-filters-with-a-list-of-key--value-arguments

    希望这可以帮助。

    【讨论】:

      猜你喜欢
      • 2019-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-04
      • 2019-05-21
      • 2021-02-19
      • 2019-06-22
      • 2018-01-28
      相关资源
      最近更新 更多