gpt4 book ai didi

graphql - 如何使用 where 子句执行 WpGraphQL 查询?

转载 作者:行者123 更新时间:2023-12-02 17:53:48 26 4
gpt4 key购买 nike

这很好用

  query QryTopics {
topics {
nodes {
name
topicId
count
}
}
}

但我想要一个过滤结果。我是 graphql 的新手,但我在这个集合上看到一个名为“where”的参数,在“first”、“last”、“after”等之后......我该如何使用它?它的类型是“RootTopicsTermArgs”,这可能是从我的架构中自动生成的。它有字段,其中之一是 bool 值的“无子项”。我想做的,是只返回带有标签的帖子的主题(Wordpress 中的自定义分类法)。基本上它阻止我在客户端上执行此操作。

data.data.topics.nodes.filter(n => n.count !== null)

有人可以指导我一个在集合中使用 where args 的好例子吗?我已经尝试了我能想到的所有语法排列。包括

  topics(where:childless:true)
topics(where: childless: 'true')
topics(where: new RootTopicsTermArgs())
etc...

显然这些都是错误的。

最佳答案

如果自定义分类法(例如主题)已注册到“show_in_graphql”并且是架构的一部分,您可以使用如下参数进行查询:

query Topics {
topics(where: {childless: true}) {
edges {
node {
id
name
}
}
}
}

此外,您可以将静态查询与变量结合使用,如下所示:

query Topics($where:RootTopicsTermArgs!) {
topics(where:$where) {
edges {
node {
id
name
}
}
}
}

$variables = {
"where": {
"childless": true
}
};
<小时/>

我推荐的一件事是使用 GraphiQL IDE,例如 https://github.com/skevy/graphiql-app ,这将通过在您键入时提供提示以及无效查询的视觉指示器来帮助验证您的查询。

您可以在此处查看使用参数查询术语的示例:https://playground.wpgraphql.com/#/connections-and-arguments

关于graphql - 如何使用 where 子句执行 WpGraphQL 查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48912739/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com