rburgst / wp-graphql-wpml

a wordpress plugin that improves wpgraphql usage together with wpml
GNU General Public License v3.0
49 stars 19 forks source link

Languages menu missing after Wordpress 6.1.1 update #38

Open achi-tricentis opened 1 year ago

achi-tricentis commented 1 year ago

After we updated to Wordpress 6.1.1, we no longer see the menu in other languages. GraphQL IDE does not retrieve the data either. GraphQL Version 1.13.7 and WPGraphQL WPML Version 1.1.0

achi-tricentis commented 1 year ago
Screenshot 2023-01-13 at 12 12 17 PM Screenshot 2023-01-13 at 12 12 03 PM
SmartyP commented 1 year ago

Confirming and following up with further details. Basically before WP 6.1.1 I could run a query like this:

query allMenus {
  menus {
    nodes {
      language
      locations
    }
  }
}

.. and I would get all of my menus (English, French, German). That response would look something like this:

{
  "data": {
    "menus": {
      "nodes": [
        {
          "language": "de",
          "locations": [
            "MENU_A"
          ]
        },
        {
          "language": "en",
          "locations": [
            "MENU_A"
          ]
        },
        {
          "language": "en",
          "locations": [
            "MENU_B"
          ]
        },
        {
          "language": "de",
          "locations": [
            "MENU_B"
          ]
        },
        {
          "language": "fr",
          "locations": [
            "MENU_B"
          ]
        },
        {
          "language": "en",
          "locations": [
            "MENU_C"
          ]
        },
        {
          "language": "fr",
          "locations": [
            "MENU_C"
          ]
        },
        {
          "language": "de",
          "locations": [
            "MENU_C"
          ]
        },
        {
          "language": "en",
          "locations": [
            "MENU_D"
          ]
        },
        {
          "language": "de",
          "locations": [
            "MENU_D"
          ]
        }
      ]
    }
  },
  "extensions": {
    "debug": [
      {
        "type": "DEBUG_LOGS_INACTIVE",
        "message": "GraphQL Debug logging is not active. To see debug logs, GRAPHQL_DEBUG must be enabled."
      }
    ]
  }
}

Now after updating to WP 6.1.1 the same query above instead gives these results:

{
  "data": {
    "menus": {
      "nodes": [
        {
          "language": "en",
          "locations": [
            "MENU_A"
          ]
        },
        {
          "language": "en",
          "locations": [
            "MENU_B"
          ]
        },
        {
          "language": "en",
          "locations": [
            "MENU_C"
          ]
        },
        {
          "language": "en",
          "locations": [
            "MENU_D"
          ]
        }
      ]
    }
  },
  "extensions": {
    "debug": [
      {
        "type": "DEBUG_LOGS_INACTIVE",
        "message": "GraphQL Debug logging is not active. To see debug logs, GRAPHQL_DEBUG must be enabled."
      }
    ]
  }
}

The issue being that the non-English menus are no longer returning via GraphQL queries.

I've tried instead querying by language like the following, but this does not work before or after 6.1.1:

query onlyGermanMenus {
  menus(where: {language: "de"}) {
    nodes {
      language
      locations
    }
  }
}

Before 6.1.1 this (^) query would return all menus and ignore the where, and after 6.1.1 this query is only returning English menus (same as if there wasn't a where query).

I'm guessing next steps are reviewing what may have changed in WordPress between WordPress 5.9 and Wordpress 6.1.1 that could've had this cascading effect. Will follow up if I can dig in further on that front.

SmartyP commented 1 year ago

In case it is helpful to anyone, our workaround for this issue was to instead use the REST API with a menus extension such that we can query for all menu locations like this: https://www.ourbackend.com/wp-json/menus/v1/locations

Then, once we know all the menu locations and languages we then query all those combinations in individual queries something like this:

query menuByLocationAndLanguage_${language}_${location} {
    menus(where: {location: ${location}, language: "${language}"}, first: 100) {
        nodes {
            language
            locations
            menuItems(where: {parentId: null}, first: 100) {
                nodes {
                    parentId
                    label
                    url
                }
            }
        }
    }
}

We then aggregate all of those responses. Basically you can query for menus so long as you provide both location and language, so since those queries work we can still leverage them - we just have to nail down all the menus and languages with the REST API instead and make many individual queries instead of just 1 like before.