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

如何使用where子句执行WpGraphQL查询?,graphql,wp-api,graphiql,Graphql,Wp Api,Graphiql,这个很好用 query QryTopics { topics { nodes { name topicId count } } } 但是我想要一个过滤的结果。我是graphql新手,但我在这个集合中看到一个名为“where”的参数,在“first”、“last”、“after”等后面。。。我怎么用这个?它的类型是“RootTopicsTermArgs”,很可能是从我的模式自动生成的。它有

这个很好用

  query QryTopics {
    topics {
      nodes {
          name
          topicId
          count
      }
    }
  }
但是我想要一个过滤的结果。我是graphql新手,但我在这个集合中看到一个名为“where”的参数,在“first”、“last”、“after”等后面。。。我怎么用这个?它的类型是“RootTopicsTermArgs”,很可能是从我的模式自动生成的。它有字段,其中一个是布尔值的“无子”字段。我想做的是,只返回带有贴子的主题(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,例如,它将通过在键入时提供提示和无效查询的可视指示器来帮助验证查询

您可以在此处看到使用参数查询术语的示例: