craftcms / craftcms/cms

[4.x]: Graph QL asset field query of matrix block is responding as fatal error

Open
#13,779 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug craft4
Dominant language
PHP
Stars
3.6k
Forks
705
Avg merge
1d 5h
Merged PRs (30d)
134

Description

What happened?
Description

We use Graph QL to query assets in matrix blocks of an entry based on user selection in the front end. It was running smoothly until upgrading to 4.5.6.1. Since the upgrade querying asset in a matrix blocks results in a fatal error. But there is another standalone asset field in the section where querying it is responding as expected.

We have a staging site that runs on Craft 4.2.5.2 where the same query is responding as expected.

Steps to reproduce
  1. Install Craft 4.5.6.1
  2. Navigate to Graph QL explorer
  3. use Graph QL query to retrieve asset field in a matrix block
Expected behavior

The response should include an array of asset details or an empty array

Request

query findProductsBySite($site: [QueryArgument]) {
  productsEntries(siteId: $site) {
    ... on products_products_Entry {
      id
      title
      productFeaturedImage {
        ... on images_Asset {
          id
          title
        }
      }
      productVariants {
        ... on productVariants_variants_BlockType {
          id
          stockcode
          productImages {
            ... on images_Asset {
              id
            }
          }
        }
      }
    }
  }
}

Response

{
  "data": {
    "productsEntries": [
      {
        "id": "12944275",
        "title": "test",
        "productVariants": []
      },
      {
        "id": "12936742",
        "title": "724",
        "productVariants": [
          {
            "id": "12936743",
            "stockcode": "724-11-5-SC",
            "productImages": []
          },
          {
            "id": "12936744",
            "stockcode": "724-11-5-PC",
            "productImages": []
          },
          {
            "id": "12936745",
            "stockcode": "724-11-5-BN",
            "productImages": []
          },
          {
            "id": "12936746",
            "stockcode": "724-11-0-SC",
            "productImages": []
          },
... so on
Actual behavior
{
  "name": "PHP Fatal Error",
  "message": "A server error occurred.",
  "code": 1,
  "error": "A server error occurred."
}
Craft CMS version

4.5.6.1

PHP version

8.1

Operating system and version

Linux 5.4.0-155-generic

Database type and version

MySQL 5.7.32

Image driver and version

Imagick (ImageMagick 6.9.10-23)

Installed plugins and versions
  • Async Queue 3.1.0
  • Element API 3.0.1.1
  • Field Manager 3.0.7
  • Linkit 4.0.4.1
  • Navigation 2.0.16
  • Neo 3.4.0
  • Redactor 3.0.3
  • Redactor Anchors 1.4.0
  • Redactor Custom Styles 4.0.3
  • Redirect manager 2.0.0
  • SEOmatic 4.0.19
  • Custom plugin 4.1.15

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the asset-field query in the GraphQL Explorer on Craft 4.5.6.1, using the provided Matrix block query, and compare it with the reported behavior on 4.2.5.2. Trace the resulting PHP fatal error and verify that querying productImages returns asset details or an empty array without a fatal response.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, mysql, php
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.