Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't retrieve Core Navigation data #187

Open
studiohic opened this issue Feb 19, 2024 · 1 comment
Open

Can't retrieve Core Navigation data #187

studiohic opened this issue Feb 19, 2024 · 1 comment
Labels
needs: reproduction This issue needs to be reproduced independently

Comments

@studiohic
Copy link

Thanks for your hardwork on this. I'm struggling to get data from CoreNavigation, CoreNavigationLink, CoreNavigationSubmenu. Please see code:

query NewQuery {
  pages {
    nodes {
      editorBlocks(flat: true) {
        __typename
        name
        ... on CoreNavigation {
          attributes {
            ref
          }
        }
        ... on CoreNavigationLink {
          attributes {
            label
            url
            title
          }
        }
        ... on CoreNavigationSubmenu {
          attributes {
            title
            url
            label
          }
        }
      }
    }
  }
}

This returns the following:

{
  "data": {
    "pages": {
      "nodes": [
        {
          "editorBlocks": []
        },
        {
          "editorBlocks": []
        },
        {
          "editorBlocks": [
            {
              "__typename": "CoreParagraph",
              "name": "core/paragraph"
            }
          ]
        },
        {
          "editorBlocks": []
        },
        {
          "editorBlocks": []
        },
        {
          "editorBlocks": []
        },
        {
          "editorBlocks": []
        },
        {
          "editorBlocks": [
            {
              "__typename": "CoreParagraph",
              "name": "core/paragraph"
            }
          ]
        },
        {
          "editorBlocks": [
            {
              "__typename": "CoreParagraph",
              "name": "core/paragraph"
            },
            {
              "__typename": "CoreParagraph",
              "name": "core/paragraph"
            },
            {
              "__typename": "CoreColumns",
              "name": "core/columns"
            },
            {
              "__typename": "CoreColumn",
              "name": "core/column"
            },
            {
              "__typename": "CoreParagraph",
              "name": "core/paragraph"
            },
            {
              "__typename": "CoreColumn",
              "name": "core/column"
            },
            {
              "__typename": "CoreParagraph",
              "name": "core/paragraph"
            },
            {
              "__typename": "CoreGroup",
              "name": "core/group"
            },
            {
              "__typename": "CoreImage",
              "name": "core/image"
            }
          ]
        }
      ]
    }
  },
  "extensions": {
    "debug": [
      {
        "type": "DEBUG_LOGS_INACTIVE",
        "message": "GraphQL Debug logging is not active. To see debug logs, GRAPHQL_DEBUG must be enabled."
      }
    ]
  }
}
@theodesp
Copy link
Member

theodesp commented Feb 20, 2024

Hello @studiohic. Thank you for the report.

After looking into this, I can see that this block is not a standard block that has queryable attributes. Its part of the Full-stack editing blocks that are generated dynamically per page.

If you look at the contents of a saved CoreNavigation block you will see that it contains only a reference:

<!-- wp:navigation {"ref":45} /-->

This means that by default it cannot be parsed using the parse_blocks function. It won't do anything.

One could try to fix this by retrieving the navigation model from the ref id (using https://developer.wordpress.org/reference/functions/wp_get_nav_menu_items/) and with adding Query Attributes that extract the menu items from the HTML or return the menu node so that users can query it.

Here is an example of how we do this with the MediaDetails attribute of the Image block

https://github.com/wpengine/wp-graphql-content-blocks/blob/main/includes/Blocks/CoreImage.php#L44-L69

Here is the block code that does this work maybe you can make a sense out of it:

https://github.com/WordPress/WordPress/blob/a4aeb7160325117db7eed9fb1277df95c1681273/wp-includes/blocks/navigation.php#L206-L231

@josephfusco josephfusco added the needs: reproduction This issue needs to be reproduced independently label Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: reproduction This issue needs to be reproduced independently
Projects
None yet
Development

No branches or pull requests

3 participants