Skip to content
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

[4.x]: GraphQL Preview - Ancestor and Parent is missing #16327

Closed
Latex88 opened this issue Dec 13, 2024 · 9 comments
Closed

[4.x]: GraphQL Preview - Ancestor and Parent is missing #16327

Latex88 opened this issue Dec 13, 2024 · 9 comments

Comments

@Latex88
Copy link

Latex88 commented Dec 13, 2024

What happened?

Description

When querying a modified entry in preview mode using GraphQL, the expected parent or ancestor data for the entry is not being returned.

The Issue only seems to ocurr when multiple entries are returned from the query.

Steps to reproduce

  1. Edit an entry that has a defined parent.
  2. Make a GraphQL request using the preview token.
  3. Include parent and ancestor fields in the query.

Expected behavior

The query should return the modified entry along with its parent and ancestor data, reflecting the hierarchy.

Actual behavior

The response does not include the parent or ancestor data for the modified entry in preview mode.

Craft CMS version

4.12.3

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

@i-just
Copy link
Contributor

i-just commented Dec 13, 2024

Hi, thanks for getting in touch!

Let me check if I understand this right. You have an entry in a structure. That entry has a parent. You edited that entry and, for example, changed the title. You let the changes autosave (but you haven’t fully saved it). You’re querying that entry via GraphQL and using the token param in order to get the entry with the latest edits. When you do that, the params you requested to be returned for the edited entry are returned (including the edited title, but the parent of that entry is not in the response even though you requested it to be returned?

@Latex88
Copy link
Author

Latex88 commented Dec 13, 2024

Hi, thanks for getting in touch!

Let me check if I understand this right. You have an entry in a structure. That entry has a parent. You edited that entry and, for example, changed the title. You let the changes autosave (but you haven’t fully saved it). You’re querying that entry via GraphQL and using the token param in order to get the entry with the latest edits. When you do that, the params you requested to be returned for the edited entry are returned (including the edited title, but the parent of that entry is not in the response even though you requested it to be returned?

Yes, correct :)

@i-just
Copy link
Contributor

i-just commented Dec 13, 2024

Thanks! I’m not able to reproduce that. Can you confirm that the parent of the entry you’re querying for has not been added during the edit that hasn’t been fully saved? Can you please share the query and response?

@Latex88
Copy link
Author

Latex88 commented Dec 13, 2024

  entries(
    section: "bueroseiten_at"
    status: "live"
    site: "at_de"
    uri: "*/remax-exclusive-wiener-neustadt*"
  ) {
    id
    isDraft
    title
    slug
    status
    uri
    enabled
    dateCreated
    language
    expiryDate
    level
    sectionHandle
    isDraft
    canonicalId
    ancestors(status: "live") {
      id
      slug
    }

    parent {
      id
      slug
    }
    ... on bueroseiten_at_default_Entry {
      page
    }
  }
}

Response:

{
                "id": "1634274",
                "isDraft": true,
                "title": "Newss",
                "slug": "news",
                "status": "live",
                "uri": "ib/remax-exclusive-wiener-neustadt/news",
                "enabled": true,
                "dateCreated": "2024-12-13T09:17:30+01:00",
                "language": "de",
                "expiryDate": null,
                "level": 2,
                "sectionHandle": "bueroseiten_at",
                "canonicalId": 782316,
                "ancestors": [],
                "parent": null,
                "page": "bueronews"
            },
            {
                "id": "796039",
                "isDraft": false,
                "title": "Service",
                "slug": "service",
                "status": "live",
                "uri": "ib/remax-exclusive-wiener-neustadt/service",
                "enabled": true,
                "dateCreated": "2023-03-09T10:36:36+01:00",
                "language": "de",
                "expiryDate": null,
                "level": 2,
                "sectionHandle": "bueroseiten_at",
                "canonicalId": 796039,
                "ancestors": [
                    {
                        "id": "782267",
                        "slug": "remax-exclusive-wiener-neustadt"
                    }
                ],
                "parent": {
                    "id": "782267",
                    "slug": "remax-exclusive-wiener-neustadt"
                },
                "page": "bueroservice"
            },

as you can see, for some reason, the parent and ancestor are not set, only on the second entry thats not a draft.

@i-just
Copy link
Contributor

i-just commented Dec 13, 2024

hmm, I’m still not able to reproduce. Any chance you could send your composer.json, composer.lock and database export to support@craftcms.com and point to the section where this entry lives?

@tommysvr
Copy link

I've been able to reproduce this on a fresh install, using Postman to query for entries in a structure.

When using a preview token param, I get back the edited/unsaved entry, but the parent is null. After removing the token param, I get back to published entry and the parent is returned as expected.

Image


Wiithout the token:

Image

@brandonkelly
Copy link
Member

Aha, I was testing using the id param to only load the specific entry that was being previewed, which is working fine, but it breaks when you are loading multiple entries at once, due to an eager-loading bug.

Craft 4.13.7 and 5.5.7 are out with a fix.

@Latex88
Copy link
Author

Latex88 commented Dec 18, 2024

Hey, i just updated to Craft 4.13.7 but now, the ancestors and parents are missing for all items in the list.
Do I need do resave or clear some caches?

@brandonkelly
Copy link
Member

@Latex88 You’ll want to clear your data caches, or invalidate GraphQL caches from the Caches utility, yes.

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

No branches or pull requests

4 participants