Cms: [3.5.x-dev] Eager loading of assets in matrixes broken in singles if you attempt to load parent

Created on 1 Jul 2020  路  5Comments  路  Source: craftcms/cms

Description

I'm back again for your daily dose of issues submitted by me 馃槄:

When you have a matrix within a single entry (which naturally doesn't ever have a parent - I'll explain why I do this later) and you try to eager load a parent as well as say an asset in a matrix it won't attempt to load the asset at all. Take the following query:

query {
  entry(section: "test") {
    parent {
      slug
    }
    ... on test_test_Entry {
      imageMatrix {
        ... on imageMatrix_image_BlockType {
          image {
            id
          }
        }
      }
    }
  }
}

It will return:

{
  "data": {
    "entry": {
      "parent": null,
      "imageMatrix": [
        {
          "image": []
        }
      ]
    }
  }
}

However, if you remove the parent selector:

query {
  entry(section: "test") {
    ... on test_test_Entry {
      imageMatrix {
        ... on imageMatrix_image_BlockType {
          image {
            id
          }
        }
      }
    }
  }
}

You will get the expected result:

{
  "data": {
    "entry": {
      "imageMatrix": [
        {
          "image": [
            {
              "id": "5"
            }
          ]
        }
      ]
    }
  }
}

Now, I fully understand that I'm not supposed to select a parent on a single and I can totally get around this problem by simply not selecting a parent in singles. This would however make me have to repeat myself in my GraphQL queries a lot as someone may want to re-use the same query for when a single page is similar to a structure or channel like so:

query ($site: [String], $section: [String], $slug: [String]) {
  entry (site: $site, section: $section, slug: $slug) {
    id
    slug
    parent {
      slug
    }

    # Index pages
    ... on aboutIndex_aboutIndex_Entry {
      subPageSections {
        ... subSections
      }
    }

    # Entry pages
    ... on about_about_Entry {
      subPageSections {
        ... subSections
      }
  }
}

This would have to become something like this, and then repeated for every non single we want to be able to fetch in the same dynamic query:

query ($site: [String], $section: [String], $slug: [String]) {
  entry (site: $site, section: $section, slug: $slug) {
    id
    slug

    # Index pages
    ... on aboutIndex_aboutIndex_Entry {
      subPageSections {
        ... subSections
      }
    }

    # Entry pages
    ... on about_about_Entry {
      parent {
    slug
      }

      subPageSections {
        ... subSections
      }
  }
}

It also worked as expected in Craft 3.4 so I think this might be a bug with the new eager loading logic in 3.5 馃槃

Steps to reproduce

  1. Create a single section
  2. Create a matrix field containing an asset
  3. Assign this field to the single section
  4. Query the section you made and the containing matrix asset field
  5. You'll get the expected result, however if you try to additionally select the parent of the single section entry it will no longer load the asset from your matrix field

Additional info

It may be related to https://github.com/spicywebau/craft-neo/issues/349 (not a craft issue) and somewhat related to #6294 although not entirely for either of them

  • Craft version: 3.5.x-dev 3596932cc042ccfc4efeb4d040611302f695ee2e
  • PHP version: 7.4.5
  • Database driver & version: PostgreSQL 12.2
  • Plugins & versions: None (Able to re-create on a completely fresh installation)
bug normal

All 5 comments

I'm unable to reproduce this.

Any chance you could zip up a database dump + your composer.lock and composer.json files, and send them over to [email protected] while referencing this issue?

I can't re-create this in a fresh installation using matrix blocks anymore. I can however re-create it when using Neo Matrix fields now, but I'm not sure if that's a Craft bug or a Neo bug at this point

Think I found the bug. Gonna keep you posted!

@Marcuzz This should be fixed now. Run composer update and you should be good to go.

Thank you guys for the awesome and quick work you're doing. We really appreciate it 鉂わ笍馃槂馃帀

Was this page helpful?
0 / 5 - 0 ratings