Skip to content

[5.7.6]: GraphQL query on an entry with a Matrix field returns duplicates of the actual Matrix blocks #17324

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

Closed
MartinSchmid2409 opened this issue May 26, 2025 · 6 comments
Assignees
Labels

Comments

@MartinSchmid2409
Copy link

What happened?

Description

Below is an actual working query. The problem is the field "lookoutArticle" which is a Matrix field. The actual entry has 5 content blocks inside the matrix field. But the GraphQL query returns lots of duplicates of each of these 5 content blocks (I checked it: same id). I´ve tried all and everything to get rid of these duplicates, but no chance. Google and ChatGPT also did not help. Did I oversee something? I just want to return the entry as it is shown in the Craft CMS admin backend. I want to see a GraphQL response with 5 entries inside the Matrix block (and not ~35).

Steps to reproduce

REQUEST:

query GetLookoutEntry {
  entry(site: "bbm_de", section: "lookout", status: "live", trashed: false, slug: "test-de") {
    slug
    ... on lookoutEntry_Entry {
      lookoutSeoTitle
      lookoutSeoMetaDescription
      lookoutHeadline
      lookoutTeaserLong
      lookoutImageMain {
        id
        url(transform: "lookoutTransformArticle")
      }
      lookoutArticle(site: "bbm_de", status: "live", trashed: false) {
        __typename
        ... on lookoutBlockText_Entry {
          lookoutBlockText {
             __typename
          }
        }
        ... on lookoutBlockImage_Entry {
          lookoutBlockImage {
            id
            siteId
          }
        }
        ... on lookoutBlockEmbeddedAsset_Entry {
          lookoutBlockEmbeddedAsset {
            id
            siteId
          }
        }
      }
    }
  }
}

RESPONSE:

{
  "data": {
    "entry": {
      "slug": "test-de",
      "lookoutSeoTitle": "Test DE Das sind die Flitterwochen",
      "lookoutSeoMetaDescription": "Test DE",
      "lookoutHeadline": "Test DE",
      "lookoutTeaserLong": "Test DE",
      "lookoutImageMain": [
        {
          "id": "8",
          "url": null
        }
      ],
      "lookoutArticle": [
        {
          "__typename": "lookoutBlockText_Entry",
          "lookoutBlockText": {
            "__typename": "lookoutBlockText_CkeditorField"
          }
        },
        {
          "__typename": "lookoutBlockText_Entry",
          "lookoutBlockText": {
            "__typename": "lookoutBlockText_CkeditorField"
          }
        },
        {
          "__typename": "lookoutBlockText_Entry",
          "lookoutBlockText": {
            "__typename": "lookoutBlockText_CkeditorField"
          }
        },
        {
          "__typename": "lookoutBlockText_Entry",
          "lookoutBlockText": {
            "__typename": "lookoutBlockText_CkeditorField"
          }
        },
        {
          "__typename": "lookoutBlockText_Entry",
          "lookoutBlockText": {
            "__typename": "lookoutBlockText_CkeditorField"
          }
        },
        {
          "__typename": "lookoutBlockText_Entry",
          "lookoutBlockText": {
            "__typename": "lookoutBlockText_CkeditorField"
          }
        },
        {
          "__typename": "lookoutBlockText_Entry",
          "lookoutBlockText": {
            "__typename": "lookoutBlockText_CkeditorField"
          }
        },
        {
          "__typename": "lookoutBlockText_Entry",
          "lookoutBlockText": {
            "__typename": "lookoutBlockText_CkeditorField"
          }
        },
        {
          "__typename": "lookoutBlockText_Entry",
          "lookoutBlockText": {
            "__typename": "lookoutBlockText_CkeditorField"
          }
        },
        {
          "__typename": "lookoutBlockText_Entry",
          "lookoutBlockText": {
            "__typename": "lookoutBlockText_CkeditorField"
          }
        },
        {
          "__typename": "lookoutBlockImage_Entry",
          "lookoutBlockImage": [
            {
              "id": "8",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockImage_Entry",
          "lookoutBlockImage": [
            {
              "id": "8",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockImage_Entry",
          "lookoutBlockImage": [
            {
              "id": "8",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockImage_Entry",
          "lookoutBlockImage": [
            {
              "id": "8",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockImage_Entry",
          "lookoutBlockImage": [
            {
              "id": "8",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockImage_Entry",
          "lookoutBlockImage": [
            {
              "id": "8",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockImage_Entry",
          "lookoutBlockImage": [
            {
              "id": "8",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockEmbeddedAsset_Entry",
          "lookoutBlockEmbeddedAsset": [
            {
              "id": "11",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockEmbeddedAsset_Entry",
          "lookoutBlockEmbeddedAsset": [
            {
              "id": "11",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockEmbeddedAsset_Entry",
          "lookoutBlockEmbeddedAsset": [
            {
              "id": "11",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockEmbeddedAsset_Entry",
          "lookoutBlockEmbeddedAsset": [
            {
              "id": "11",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockEmbeddedAsset_Entry",
          "lookoutBlockEmbeddedAsset": [
            {
              "id": "11",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockEmbeddedAsset_Entry",
          "lookoutBlockEmbeddedAsset": [
            {
              "id": "11",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockEmbeddedAsset_Entry",
          "lookoutBlockEmbeddedAsset": [
            {
              "id": "11",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockEmbeddedAsset_Entry",
          "lookoutBlockEmbeddedAsset": [
            {
              "id": "34",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockEmbeddedAsset_Entry",
          "lookoutBlockEmbeddedAsset": [
            {
              "id": "34",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockEmbeddedAsset_Entry",
          "lookoutBlockEmbeddedAsset": [
            {
              "id": "34",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockEmbeddedAsset_Entry",
          "lookoutBlockEmbeddedAsset": [
            {
              "id": "34",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockEmbeddedAsset_Entry",
          "lookoutBlockEmbeddedAsset": [
            {
              "id": "34",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockText_Entry",
          "lookoutBlockText": {
            "__typename": "lookoutBlockText_CkeditorField"
          }
        },
        {
          "__typename": "lookoutBlockEmbeddedAsset_Entry",
          "lookoutBlockEmbeddedAsset": [
            {
              "id": "34",
              "siteId": 1
            }
          ]
        },
        {
          "__typename": "lookoutBlockText_Entry",
          "lookoutBlockText": {
            "__typename": "lookoutBlockText_CkeditorField"
          }
        },
        {
          "__typename": "lookoutBlockText_Entry",
          "lookoutBlockText": {
            "__typename": "lookoutBlockText_CkeditorField"
          }
        },
        {
          "__typename": "lookoutBlockText_Entry",
          "lookoutBlockText": {
            "__typename": "lookoutBlockText_CkeditorField"
          }
        },
        {
          "__typename": "lookoutBlockText_Entry",
          "lookoutBlockText": {
            "__typename": "lookoutBlockText_CkeditorField"
          }
        },
        {
          "__typename": "lookoutBlockText_Entry",
          "lookoutBlockText": {
            "__typename": "lookoutBlockText_CkeditorField"
          }
        }
      ]
    }
  }
}

Expected behavior

GraphQL response: Matrix field entries not duplicated lots of times.

Actual behavior

GraphQL response: Matrix field entries ARE duplicated lots of times.

Craft CMS version

5.7.6

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

"Embedded Assets"
"CKEditor"
"Multi Translator"
"Image Resizer"

@MartinSchmid2409
Copy link
Author

Okay, I have solved this, and I think it is a bug. Or at least unintentional or unwanted behavior.

This is caused because of Versioning introduced for Matrix fields as of Craft 5.7:
https://craftcms.com/docs/5.x/reference/field-types/matrix.html#versioning

When I disabled "Enable versioning for entries in this field" on field "lookoutArticle" I didn´t get duplicates anymore from GraphQL response. But onyl for new entries created after altering this setting.

So, GraphQL as a default, returns all versions of the entries of a Matrix field. This behavior cannot be intentional. From a practical view, it does not make any sense.

Desired behavior: GraphQL should only return the latest versions of the entries of a Matrix field no matter if "Enable versioning for entries in this field" is enabled or not.

@MartinSchmid2409
Copy link
Author

Additional question: Is there any query argument I can add to the GraphQL to omit having versioned Matrix field entries in the response? If no, there should be one, at least ;)

@yingban
Copy link

yingban commented May 27, 2025

@MartinSchmid2409
I had the same as you, what was weird is that if you uncheck the versioning, the data remains duplicated.
So there might be a bug.

@i-just i-just self-assigned this May 27, 2025
@i-just
Copy link
Contributor

i-just commented May 27, 2025

Hi, thanks for getting in touch and for all the info.

Is there any query argument I can add to the GraphQL to omit having versioned Matrix field entries in the response?

You can add revisions: false to your lookoutArticle query to exclude revisions.

I’m looking into this and will update this issue once I have more info.

@i-just
Copy link
Contributor

i-just commented May 28, 2025

I raised a PR to improve this.

@brandonkelly
Copy link
Member

Craft 5.7.8 is out with that fix. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants