【问题标题】:Incorrectly selected data in the query查询中选择的数据不正确
【发布时间】:2021-07-29 03:23:36
【问题描述】:

只需要包含 EmailMarketing 标签的文章。

我可能在标签上进行了错误的搜索,因为它是一个值数组,而不是单个对象,但我不知道如何正确地做,我只是在学习 graphql。任何帮助将不胜感激

查询:

query {
  enArticles {
    title
    previewText
    tags(where: {name: "EmailMarketing"}){
      name
    }
  }
}

结果:

{
    "data": {
        "enArticles": [
            {
                "title": "title1",
                "previewText": "previewText1",
                "tags": [
                    {
                        "name": "EmailMarketing"
                    },
                    {
                        "name": "Personalization"
                    },
                    {
                        "name": "Advertising_campaign"
                    }
                ]
            },
            {
                "title": "title2",
                "previewText": "previewText2",
                "tags": [
                    {
                        "name": "Marketing_strategy"
                    },
                    {
                        "name": "Marketing"
                    },
                    {
                        "name": "Marketing_campaign"
                    }
                ]
            },
            {
                "title": "article 12",
                "previewText": "article12",
                "tags": []
            }
        ]
    }
}

【问题讨论】:

  • 这实际上取决于您查询的 API。这是 Hasura 数据库还是其他什么?

标签: graphql


【解决方案1】:

我相信您首先需要在您的 GraphQL 架构中编写一个等式运算符here 有一个很好的解释。

一旦你添加了一个相等运算符——比如说,_eq——你可以像这样使用它:

query {
  enArticles {
    title
    previewText
    tags(where: {name: {_eq: "EmailMarketing"}}){
      name
    }
  }
}

具体来说,您需要创建一个过滤器和解析器。

here 的例子可能会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-31
    • 1970-01-01
    • 1970-01-01
    • 2020-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多