Closed tremby closed 10 months ago
When searching for similar issues I came across this comment from Brandon:
[other bug] is happening because
photo
and a few other fields have special cases in the eager loading logic (e.g. entries’author
fields), so we need to identify all of those and avoid using eager-loading aliases in those cases, from the GraphQL side.
Seems relevant.
Entries already have author
properties. So at best, maybe the error could be improved so that it clarifies the conflict. But I don’t think it should be possible to override existing properties with aliases.
But I don’t think it should be possible to override existing properties with aliases.
Aliases don't override anything. I don't see why there should be any conflict here as far as Craft is concerned. If I wanted the native author field in addition I could ask for author: authorEntry { title } craftAuthor: author { username }
or similar. This is all allowed by the GQL spec so I don't expect an error from Craft.
The problem is that Craft automatically eager-loads any relation fields that are queried in GraphQL, using the same system used to eager-load native properties like author
. Currently element classes aren’t able to differentiate between a core eager-loading handle and an alias, so all craft\elements\Entry::setEagerLoadedElements()
sees is that author
is getting eager-loaded, and doesn’t know author
is just a custom alias that was being used for an authorEntry
custom field. So it assumes that the passed-in element“s” are the entry’s author.
I was able to fix this for Craft 5, by passing the actual eager-load plan to setEagerLoadedElements()
, so elements can access the original eager-loading handle.
That’s a breaking change though, so there’s no way we can fix it for Craft 4.x.
OK, thanks.
So would there also be an issue if someone aliased the Craft author
field to something else? Would craftAuthor: author { username }
not eager-load?
Correct, because this condition would fail:
That will also be resolved by the Craft 5 change, though.
Craft 5.0.0-alpha.4 is out with that fix.
What happened?
Description
I'm getting an internal server error when I attempt to alias an entries field to the identifier
author
.Steps to reproduce
authors
. Fields don't matter.recipes
authorEntry
) so the content author can choose anauthors
entry.authors
entry and arecipes
entry (mine has slugthe-last-word
), in which the author is selected.Expected behavior
Getting the author entry's title back, looking something like
Actual behavior
Notes:
author
field?Also:
Craft CMS version
4.5.11.1
PHP version
8.2.7
Operating system and version
Not sure exactly other than that it's linux, but it's running in a docker container based on
php:8.2-fpm
Database type and version
Postgres 14
Image driver and version
Imagick
Installed plugins and versions