What I want to do
Imagine I have a shopping list app that lets you create multiple lists of items with a cost property. I’d like to sort the lists by the totals of the items in the list. Is this something that can be done in GraphQL or even DQL?
This may seem like a trivial problem with a few lists, but we have something similar for a use case at our company, and some clients have thousands of “shopping lists” with many items. We’d like to create a table where they can easily sort these lists by item total with pagination.
What I did
I’ve searched and found this: Possible to sort by count of Aggregate field?
It looks like this might not be possible.
To start off with I was playing around with dgraph cloud and came up with this query:
query GetUserAndLists {
getUser(id: "0x2") {
lists {
title
itemsAggregate {
count
costSum
}
}
}
}
This produces this result:
{
"getUser": {
"lists": [
{
"id": "0x3",
"title": "List1",
"itemsAggregate": {
"count": 3,
"costSum": 617.65
}
},
{
"id": "0x4",
"title": "List2",
"itemsAggregate": {
"count": 1,
"costSum": 980.43
}
}
]
}
}
Is there a way to sort the lists by costSum
in itemsAggregate
?