WP-API / widgets-endpoints

Experimental WordPress REST API Widgets endpoints.
7 stars 1 forks source link

Filter widgets by certain sidebar doesn't work with GraphQL #7

Open mwardew opened 5 years ago

mwardew commented 5 years ago

Hello.

I use Gatsby, Wordpress, plugin for gatsby gatsby-source-wordpress and this wp-api-menus-widgets-endpoints plugin.

My goal is to access widgets that belongs to certain sidebar - home_right_1.

Inside endpoint description it should work and it works.. but I can't create right GraphQL query - "Limit result set to widgets assigned to this sidebar."

Endpoint:

    "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"
            }
        }
}

This works in browser - output is exactly what I need

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

However I have a problem with GraphQL query. I thought I can do something like this.

{
  allWordpressWpWidgets( filter: {
      sidebar: {
          eq: "home_right_1"
      }
  } ) {
    edges {
      node {
        title
      }
    }
  }
}

It doesn't work.. But if I want for example only sticky posts I can easily do that.

{
  allWordpressPost( filter: {
      sticky: {
          eq: true
      }
  } ) {
    edges {
      node {
        title
      }
    }
  }
}

Is possible to get only widgets that belongs to sidebar or not?

Thank you