wp-graphql / wp-graphql

:rocket: GraphQL API for WordPress
https://www.wpgraphql.com
GNU General Public License v3.0
3.63k stars 440 forks source link

menuItems query "where" location is still returning ALL items from all menus #1822

Closed teetlaja closed 2 years ago

teetlaja commented 3 years ago

So it always worked for me but for some reason menuItems is returning all Menu items from everywhere. My query is

query getNavItems {
  menuItems(where: {location: PRIMARY}) {
    nodes {
      title
      path
      label
      locations
    }
  }
}

And my response still is>

{
  "data": {
    "menuItems": {
      "nodes": [
        {
          "title": null,
          "path": "/register/",
          "label": "Register",
          "locations": null
        },
        {
          "title": null,
          "path": "/",
          "label": "Home",
          "locations": [
            "PRIMARY"
          ]
        },
        {
          "title": null,
          "path": "/support/",
          "label": "Support",
          "locations": null
        },
        {
          "title": null,
          "path": "/blog/",
          "label": "Blog",
          "locations": [
            "PRIMARY"
          ]
        },
        {
          "title": null,
          "path": "/try/",
          "label": "Try",
          "locations": null
        },
        {
          "title": null,
          "path": "/about/",
          "label": "About",
          "locations": [
            "PRIMARY"
          ]
        },
        {
          "title": null,
          "path": "/contact/",
          "label": "Contact",
          "locations": [
            "PRIMARY"
          ]
        },
        {
          "title": null,
          "path": "/pricing/",
          "label": "Pricing",
          "locations": [
            "PRIMARY"
          ]
        },
        {
          "title": null,
          "path": "/try/",
          "label": "Try",
          "locations": [
            "PRIMARY"
          ]
        },
        {
          "title": null,
          "path": "/pricing/",
          "label": "Pricing",
          "locations": [
            "PRIMARY"
          ]
        }
      ]
    }
  },
  "extensions": {
    "debug": [
      {
        "type": "DEBUG_LOGS_INACTIVE",
        "message": "GraphQL Debug logging is not active. To see debug logs, GRAPHQL_DEBUG must be enabled."
      }
    ]
  }
}

I have registered one extra nav but i suppose this doesn't affect.

I don't have any plugins which could affect navigation menus. All plugins and examples are from WPGraphQL docs.

If i use menu.menuItems request hierarchy then i can get right menu but singe page is going to have 7 translations, i can't afford those mistakes - i need to query menu items by location. I'm having WPGraphQL up-to-date.

jasonbahl commented 3 years ago

@teetl6 thanks for reporting. Let me see if I can replicate this behavior.

teetlaja commented 3 years ago

@teetl6 thanks for reporting. Let me see if I can replicate this behavior.

Thanks, if additional information needed, let me know. WordPress version was 5.7 and request was made with WPGraphQL IDE.

jasonbahl commented 3 years ago

@teetl6 was it working as expected and suddenly had a change in behavior? If so, do you know what version of WPGraphQL was working and what version it stopped working?

teetlaja commented 3 years ago

@teetl6 was it working as expected and suddenly had a change in behavior? If so, do you know what version of WPGraphQL was working and what version it stopped working?

No, this is on clean install and appeared with WPGrahpQL 1.2.8 and 1.3.x as well - updating didn't resolve the problem.

jasonbahl commented 3 years ago

Ok, thanks for the information. Looking into it.

teetlaja commented 3 years ago

I've tried now many things - deleted menus and menuItems, created them again, turned off WPGraphQL plugin (with data erasing enabled) etc etc and still nothing new. Except debugging gives me this:

"errors": [
    {
      "message": "Field \"menuItems\" argument \"where\" requires type MenuLocationEnum, found \"PRIMARY\"; Did you mean the enum value PRIMARY?",
      "extensions": {
        "category": "graphql"
      },
      "locations": [
        {
          "line": 2,
          "column": 31
        }
      ]
    }
  ],

My query was copied from wpgraphql site

query MENU_ITEMS {
  menuItems(where: {location: "PRIMARY"}) {
    nodes {
      key: id
      parentId
      title: label
      url
    }
  }
}

Thing is that now i even can't choose menu location which to query.

Theme is WordPress Twenty twenty-one child theme created with Child theme configuratior.

teetlaja commented 3 years ago

But when i removed " from location, then i got returned all menu Items, even if i change menu location.

jasonbahl commented 3 years ago

@teetl6 try changing your query to:

query MENU_ITEMS {
  menuItems(where: {location: PRIMARY}) {
    nodes {
      key: id
      parentId
      title: label
      url
    }
  }
}

The key change being "PRIMARY" to PRIMARY without the quotes.

When an ENUM value is used within the Query string, it shouldn't have the quotes around it, otherwise it evaluates as a String, and not an Enum.

markkelnar commented 3 years ago

Hello @teetl6 , I'm curious about the "locations": nullyou are seeing. Can you use wp-cli to query the menu locations? Like wp menu location list

teetlaja commented 3 years ago

Hello @teetl6 , I'm curious about the "locations": nullyou are seeing. Can you use wp-cli to query the menu locations? Like wp menu location list

@markkelnar It responds me this - bottom-menu is declared by me in Child theme configuration. Parent theme is Twenty-twentyone +-------------+----------------+ | location | description | +-------------+----------------+ | primary | Primary menu | | footer | Secondary menu | | bottom-menu | Bottom menu | +-------------+----------------+

teetlaja commented 3 years ago

@jasonbahl and @markkelnar I've tried previous steps but found out that IF I deactivate WPGraphQL WPML extension, the problem goes away. If i'm activating this again, it comes back.

If WPGraphQL WPML extension is active then all menu items are displayed no matter if the where: location: is added in query or not.

jasonbahl commented 3 years ago

@teetl6 interesting. Thanks for the added context about WPML. We've had other reports with WPML causing problems. I've applied for a developer license for WPML so I can try and help debug issues, but I would also recommend opening an issue on their end. Their plugin is clearly altering behavior of menus in unexpected ways.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

This issue has been automatically closed because it has not had recent activity. If you believe this issue is still valid, please open a new issue and mark this as a related issue.

justlevine commented 2 years ago

Closing as duplicate of #1305

furai commented 1 year ago

I'm getting the exact same behaviour. When trying to query for a menu using location in where clause and that location has no menu assigned to it - I'm getting all menus by default. I've disabled all plugins except for WPGraphQL and it still kept happening. What could be the cause here?

justlevine commented 1 year ago

@furai please open a new bug report with all the requested information so we can give it our full attention 🙏 (Unless this is an issue with WPML, in which case you can follow progress in #1305 )