wpengine / wp-graphql-content-blocks

Plugin that extends WPGraphQL to support querying (Gutenberg) Blocks as data
https://faustjs.org/docs/gutenberg/wp-graphql-content-blocks
GNU General Public License v2.0
111 stars 14 forks source link

Fetching plugin blocks #141

Closed lucasBruma closed 1 year ago

lucasBruma commented 1 year ago

Hi! I’m trying to fetch and render LearnDash blocks. I’m doing the following query:

query GetPageData {
    page(id:“cG9zdDo5”) {
    id
    editorBlocks(flat:true) {
      name
      __typename
    }
  }
}

And getting the following result:

{
  “data”: {
    “page”: {
      “id”: “cG9zdDo5”,
      “editorBlocks”: [
        {
          “name”: “learndash/ld-profile”,
          “__typename”: “LearndashLdProfile”
        }
      ]
    }
  }
}

Instead of getting the whole component flattened tree, I only get the top one. I’m not a WordPress expert, so I’m not sure what’s happening here or how I can customize LearnDash so I can query it with GraphQL. Any input on how to do it helps, thanks!

theodesp commented 1 year ago

Hey @lucasBruma. I had to take a look at how LearnDash saves the blocks in the database.

Unfortunately it doesn't do it properly. It only saves an shortcode parameter and nothing else so parsing the block will return nothing.

Screenshot 2023-07-27 at 11 53 43

Upon closer look it seems that it does not declare how the editor will extract the block properties from the markup but instead it uses some internal mechanism to resolve the data.

Also the LearndashLdProfile does not contain any innerBlocks as far as I can tell.

You can use the following query to get some extra info but it would be all useless:

editorBlocks {
        apiVersion
        name
        ... on LearndashLdProfile {
          attributes {
            perPage
            className
            expandAll
            showQuizzes
            userId
            order
            showSearch
            showHeader
            order
            orderby
          }
          innerBlocks {
            renderedHtml
          }
        }

TBH in the current state I don't think that LearnDash blocks are supported out of the box sadly.

theodesp commented 1 year ago

I will keep this issue in a couple of days for feedback.

lucasBruma commented 1 year ago

Hi @theodesp, thank you for your help. What do you think is the best approach in these cases? Do you think using their API to get the data (e.g.: profile info) and rendering it with my custom components is best? Or there's anything else that may be simpler? Also, asking just in case, do you know any LMS plugin that fits better with wp-graphql-content-blocks?

Thank you.

theodesp commented 1 year ago

Hey @lucasBruma. I'm not familiar with the Learndash internals so I cannot really help you here. If Learndash was storing the block attributes the way that Gutenberg Core builds its blocks then this would be quite straightforward.

theodesp commented 1 year ago

TBH. If i were to try to implement an LMS in Headless, I would just declare my own custom post types with ACF or Genesis Custom Blocks which are both supported with this plugin.

Here is a hypothetical entity relationship diagram for an LMS:

CPTS

Course: Student Instructor Admin Lesson Quiz Assignment Grade Forum Resource

mindctrl commented 1 year ago

Hi all, I'm also not familiar enough with LearnDash to provide much help here, but I did run across this Gist to add LearnDash data to WPGraphQL. Hopefully that helps.

I don't think there's anything actionable here at the moment for this plugin, so I'll close this out. But please reopen if you continue to explore and run into any issues @lucasBruma!