如何为WordPress边栏创建GraphQL查询?

时间:2019-06-24 15:18:30

标签: wordpress graphql gatsby wordpress-rest-api

我将Gatsby,Wordpress,gatsby插件gatsby-source-wordpress和wordpress https://github.com/WP-API/wp-api-menus-widgets-endpoints的插件用于小部件端点。

我的目标是访问属于某些侧边栏的窗口小部件- home_right_1

内部端点描述应该起作用并且可以起作用。.但是我无法创建正确的GraphQL查询-“将结果集限制为分配给该边栏的小部件。”

我认为我可以稍微传递参数“侧边栏”,但它不起作用。我对GraphQL还是很缺乏经验。

端点:

"/wp/v2/widgets": {
    "namespace": "wp/v2",
    "methods": [
        "GET",
        "POST"
    ],
    "endpoints": [
        {
            "methods": [
                "GET"
            ],
            "args": {
                "context": {
                "required": false,
                "default": "view",
                "description": "Scope under which the request is made; determines fields present in response.",
                "type": "string"
            },
            "page": {
                "required": false,
                "default": 1,
                "description": "Current page of the collection.",
                "type": "integer"
            },
            "per_page": {
                "required": false,
                "default": 10,
                "description": "Maximum number of items to be returned in result set.",
                "type": "integer"
            },
            "search": {
                "required": false,
                "description": "Limit results to those matching a string.",
                "type": "string"
            },
            "sidebar": {
                "required": false,
                "description": "Limit result set to widgets assigned to this sidebar.",
                "type": "string"
            }
        }
}

这在浏览器中有效-输出正是我所需要的

wp-json/wp/v2/widgets?sidebar=home_right_1

如何更正此查询?

{
  allWordpressWpWidgets( ???sidebar: {}??? ) {
    edges {
      node {
        title
      }
    }
  }
}

谢谢

0 个答案:

没有答案