Hca*_*tek 2 wp-api graphql graphiql
这很好
query QryTopics {
topics {
nodes {
name
topicId
count
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是我想要一个过滤的结果。我是graphql的新手,但是我在此集合上看到一个名为“ where”,“ first”,“ last”,“ after”等之后的参数……我该如何使用?它的类型是'RootTopicsTermArgs',可能是从我的架构自动生成的。它具有字段,其中之一是布尔值的“无子级”。我正在尝试做的是仅返回带有帖子标记的主题(Wordpress中的自定义分类法)。基本上,它阻止了我在客户端上执行此操作。
data.data.topics.nodes.filter(n => n.count !== null)
Run Code Online (Sandbox Code Playgroud)
谁能指导我一个在集合中使用where args的好例子?我已经尝试过我能想到的所有语法组合。包括
topics(where:childless:true)
topics(where: childless: 'true')
topics(where: new RootTopicsTermArgs())
etc...
Run Code Online (Sandbox Code Playgroud)
显然,这些都是错误的。
小智 5
如果自定义分类法(例如主题)已注册到“ show_in_graphql”并且是您的架构的一部分,则可以使用类似以下的参数进行查询:
query Topics {
topics(where: {childless: true}) {
edges {
node {
id
name
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
此外,您可以将静态查询与变量结合使用,如下所示:
query Topics($where:RootTopicsTermArgs!) {
topics(where:$where) {
edges {
node {
id
name
}
}
}
}
$variables = {
"where": {
"childless": true
}
};
Run Code Online (Sandbox Code Playgroud)
我建议的一件事是使用GraphiQL IDE,例如https://github.com/skevy/graphiql-app,这将通过在您键入时提供提示以及无效查询的可视指示器来帮助验证查询。
您可以在此处查看使用参数查询术语的示例:https : //playground.wpgraphql.com/#/connections-and-arguments
| 归档时间: |
|
| 查看次数: |
1227 次 |
| 最近记录: |