【问题标题】:How to filter on entityBundle using graphql query in drupal如何在drupal中使用graphql查询过滤entityBundle
【发布时间】:2020-05-29 16:56:03
【问题描述】:

我正在使用 Drupal 8 的 GraphQl api。不幸的是,我对这两种技术都不太了解。

我有以下查询

query {
  nodeQuery (offset: 0, limit: 23) {
    entities {
      entityLabel
      entityBundle
      entityId
    }
    count
  }
}

返回看起来像这样的东西

{
  "data": {
    "nodeQuery": {
      "entities": [
        {
          "entityLabel": "Frontpage",
          "entityBundle": "section_page",
          "entityId": "20"
        },
      ....

但是,返回的一些实体不是 section_page 实体,所以我想做一个过滤器,允许我将它们过滤掉。

我做了以下

query {
  nodeQuery (offset: 0, limit: 23,filter: {conditions: {field: "entityBundle", value: "section_page", operator: EQUAL}}) {
    entities {
      entityLabel
      entityBundle
      entityId
    }
    count
  }
}

这是行不通的,我真的不希望它这么多,因为显然 entityBundle 不是节点的子节点,所以我应该以某种方式过滤实体内部的 entityBundle。还没想好怎么弄

我在运行该查询时遇到的错误是

{
  "errors": [
    {
      "message": "Internal server error",
      "category": "internal",
      "locations": [
        {
          "line": 32,
          "column": 5
        }
      ],
      "path": [
        "nodeQuery",
        "entities"
      ]
    },
    {
      "message": "Internal server error",
      "category": "internal",
      "locations": [
        {
          "line": 37,
          "column": 5
        }
      ],
      "path": [
        "nodeQuery",
        "count"
      ]
    }
  ],
  "data": {
    "nodeQuery": {
      "entities": null,
      "count": null
    }
  }
}

【问题讨论】:

    标签: graphql drupal-8


    【解决方案1】:

    好的,想通了,出乎意料

    query {
      nodeQuery (offset: 0, limit: 23, filter: {conditions: [
        {operator: EQUAL, field: "type", value: ["section_page"]}]}) {
        entities {
          entityLabel
          entityBundle
          entityId
        }
        count
      }
    }
    

    因为该字段的类型似乎也与 entityBundle 值相同。

    【讨论】:

      猜你喜欢
      • 2018-05-31
      • 2021-12-17
      • 2019-02-06
      • 2018-04-14
      • 1970-01-01
      • 2019-11-28
      • 2018-08-29
      • 2019-12-29
      • 2019-04-24
      相关资源
      最近更新 更多