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
GraphQL returning all children from a structure when requesting multiple entry types (3.4.0-RC3) #5481
Comments
The issue occurs because For example, if it were an entry field or a matrix field, this would work because internally relational fields resolve to be element queries so that you can apply more parameters to them. There was a similar issue for Matrix fields (#5008), which looks the same as your problem, but it cannot be solved the same way. As most GraphQL querying issues, this dead-ends sinceGraphQL is wrapping around element queries, so is often limited by the element query's features. The best approach here would be if Craft itself had a concept of alias in element queries, which is an issue I'll bring up internally and then update this issue. |
@samput it's still possible, however, to fetch all the children and then just differentiate or sort the data on the frontend. For example: {
quarters: entries(section: "pipeline", type: "quarter") {
id
title
platforms: children {
id
title
children {
__typename
id
title
}
}
}
} would produce {
"data": {
"quarters": [{
"id": "14",
"title": "Q1 2020",
"platforms": [{
"id": "136",
"title": "Platform Name",
"children": [{
"__typename": "pipelineSection_ongoing_Entry",
"id": "155",
"title": "Q1 2020 - Platform Name - Ongoing"
},
{
"__typename": "pipelineSection_monthly_Entry",
"id": "158",
"title": "Q1 2020 - Platform Name - January"
},
{
"__typename": "pipelineSection_monthly_Entry",
"id": "161",
"title": "Q1 2020 - Platform Name - February"
},
{
"__typename": "pipelineSection_monthly_Entry",
"id": "164",
"title": "Q1 2020 - Platform Name - March"
}
]
}]
},
{
"id": "17",
"title": "Q2 2020",
"platforms": []
},
{
"id": "20",
"title": "Q3 2020",
"platforms": []
},
{
"id": "23",
"title": "Q4 2020",
"platforms": []
}
]
}
} |
Thanks @andris-sevcenko for looking in to this. Yeah it's not a deal breaker, my plan was to separate them on the front-end by type, would be nice to have the aliases, but it's not the end of the world. |
@samput FWIW I see the benefit in offloading such operation to the query itself so you don't have to deal with that in the front-end logic, so I'm keeping this issue open until we come to a decision about it. |
@samput we're planning on adding aliasing support for element queries in 3.5, which will resolve this in a more elegant manner. |
Alright, just added this for Craft 3.5! |
Description
Using Craft CMS version 3.4.0-RC3. When querying children by type from a structure with GraphQL it returns all children when requesting multiple types.
Steps to reproduce
I have a section 'Pipeline' with a structure set up like so:
GraphQL query - multiple children types:
Response - multiple children types:
For both
ongoing
andmonthly
it returns all the children.However if I only request one child type, it works as expected e.g.
GraphQL query - ongoing children type:
Response - ongoing children type:
GraphQL query - monthly children type:
Response - monthly children type:
Additional info
The text was updated successfully, but these errors were encountered: