For a tree-like collection, I know you can query for parent
and children
in the graphQL API. But is it possible to query for siblings
somehow?
I know I can ask for the children of its parent, something like:
query MyQuery {
allBasicPages {
id
title
siblings: parent {
children {
id
title
}
}
}
}
and get back results like
{
"id": "48803150",
"title": "Draft Page: PREVIEW",
"siblings": {
"children": [
{
"id": "48803150",
"title": "Draft Page: PREVIEW"
},
{
"id": "49657859",
"title": "Teacher Professional Development"
},
{
"id": "49629739",
"title": "Learning Resources"
},
{
"id": "49661520",
"title": "Early Elementary Science Partnership"
},
{
"id": "49659082",
"title": "Field Ambassadors"
},
{
"id": "48910205",
"title": "N.W. Harris Learning Collection Update"
}
]
}
},
but two issues…
s
-
the resulting siblings still nested under a leftover
children
node, which in the code will becomeself.siblings.children
instead of justself.siblings
. This is especially confusing for other editors who don’t look at the raw GraphQL, because it makes it look like the cousins rather than siblings ofself
(i.e.siblings.children
is actually not their children, just the siblings themselves, but the quirkiness of GraphQL makes them seem otherwise). -
self
is included insiblings.children
(the record in question should not be a sibling of itself). I thought about using a@directive
to try to filter for “sibling.child.id is not self.id” but I can’t figure out if the GraphQL syntax allows that sort of comparison rather than a straight boolean.
It seems like this is doable by adding a custom sibling resolver, but if I understand that article right, it’s something that can only be done on the server side (i.e. by you fantastic people)? If this should be a feature request instead of a question, please let me know or just convert it to one.
Thanks!