craftcms / gatsby-source-craft

Gatsby source plugin for Craft CMS.
MIT License
54 stars 13 forks source link

Neo matrix data not retrieved after a depth of 3 items #22

Closed andrewmumblebee closed 3 years ago

andrewmumblebee commented 3 years ago

Description

Hi,

I've hit an issue with this plugin where it seems like the depth of the graph is limited.

I'm currently using a neo matrix, which was working fine with the original gatsby-source-graphql plugin.

This is what my query looks like in Gatsby


query MyQuery ($id:StringQueryOperatorInput) {
  craftWorkshopsWorkshopEntry(id: $id) {
    neoLP {
      ... on Craft_neoLP_ctas_BlockType {
         horizontalAlignment
         children {
        ... on Craft_neoLP_cta_BlockType {
        label
          }
        }
      }

      ... on Craft_neoLP_columns_BlockType {
        children {
          ... on Craft_neoLP_column_BlockType {
            rightColumnFirstMobile
            children {
              ... on Craft_neoLP_ctas_BlockType {
                children {
                  ... on Craft_neoLP_cta_BlockType {
                    pageLink
                  }
                }
              }
              ... on Craft_neoLP_richtext_BlockType {
                richtext
              }
            }
          }
        }
      }
    }
  }
}

The matrix (ctas) block when placed at the root of the matrix returns its data correctly.

Here is a sample response.

{
  "data": {
    "craftWorkshopsWorkshopEntry": {
      "neoLP": [
        {
          "children": [
            {
              "rightColumnFirstMobile": false,
              "children": [
                {
                  "richtext": null
                },
                {
                  "children": []
                },
                {
                  "richtext": null
                },
                {
                  "richtext": null
                },
                {
                  "children": []
                },
                {
                  "richtext": null
                },
                {
                  "children": []
                }
              ]
            },
            {
              "rightColumnFirstMobile": false,
              "children": []
            }
          ]
        },
        {
          "horizontalAlignment": "left",
          "children": [
            {
              "label": "Test"
            }
          ]
        }
      ]
    }
  }
}

Rebuilding this within CraftCMS using the graphiql UI works fine and so does the standard gatsby-source-graphql plugin.

Steps to reproduce

  1. Create a neo matrix with a depth of more than 3 (not 100% sure what depth breaks)
  2. See if data is returned

Additional info

Thanks for any help you can provide

andris-sevcenko commented 3 years ago

The reason it worked before with the gatsby-graphql-source plugin is because the plugin just executed all the GraphQL queries on every site build, as opposed to building a data store and just adding new data to it on subsequent builds.

Matrix blocks and Neo block types are not queryable directly with Craft's GraphQL API and are not exposed as stand-alone types for Gatsby, so the source toolkit can't convert them to Nodes for Gatsby. So, when creating the data store, the toolkit can't replace the nesting relationships in a simple way.

I'm assuming Gatsby hits some nesting level limitations - perhaps @vladar can confirm if it's true.

vladar commented 3 years ago

@andris-sevcenko The GraphQL toolkit prevents recursive fragments (in generateDefaultFragments function). For deep nesting, you should provide custom fragments of the expected depth. So in theory, if Craft plugin supports custom fragments - it should be possible to via additional config.

andris-sevcenko commented 3 years ago

Thank you, @vladar!

@andrewmumblebee you'll want to take a look at the documentation here - hope this helps!