[4.x]: fragments before children return incorrect graphql results
Open
@brianjhanson is already working on this.
Since Jan 26, 2023.
bug
craft4
- Dominant language
- PHP
- Stars
- 3.6k
- Forks
- 705
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 134
Description
What happened?
Description
When performing a nested graphql query with fragments, the order of operation matters when it shouldn't. First reported in #11918 but fell off the radar a bit.
Steps to reproduce
Given a site with a section called structure and a handful of entries populated

query {
entries(section:"structure", level:1) {
...sharedFields
children(type:"nested") {
id
title
}
}
}
fragment sharedFields on EntryInterface {
id
title
typeHandle
}
Expected behavior
Is expected to return
{
"data": {
"entries": [
{
"children": [
{
"id": "47",
"title": "Nested Type"
}
],
"id": "39",
"title": "Top Level Item",
"typeHandle": "default"
},
{
"children": [],
"id": "41",
"title": "Second Top Level Item",
"typeHandle": "default"
}
]
}
}
Actual behavior
{
"data": {
"entries": [
{
"id": "39",
"title": "Top Level Item",
"typeHandle": "default",
"children": [
{
"id": "43",
"title": "Child"
},
{
"id": "45",
"title": "Child Two"
},
{
"id": "47",
"title": "Nested Type"
}
]
},
{
"id": "41",
"title": "Second Top Level Item",
"typeHandle": "default",
"children": []
}
]
}
}
Work around
Moving the fragment above children will cause the correct data to be returned.
{
entries(section: "structure", level: 1) {
children(type: "nested") {
id
title
}
...sharedFields
}
}
fragment sharedFields on EntryInterface {
id
title
typeHandle
}
Craft CMS version
4.3.6.1
PHP version
N/A
Operating system and version
N/A
Database type and version
N/A
Image driver and version
N/A
Installed plugins and versions
N/A
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.