aggregates of list with various filters

I know there are aggregates and have worked with them already. But so far, aggregates work somewhat only on a "row"-level of a resource (hope I got that correct) Is there an easy way to support on "resource"-level? example: - resource: offer - attribute: price i have a list of offers that we fetch via GraphQL.
| offer name | offer price |
----------------------------
| offer 1 | $1000
| offer 2 | $2000
| offer 3 | $5000
| offer name | offer price |
----------------------------
| offer 1 | $1000
| offer 2 | $2000
| offer 3 | $5000
What's the easiest way to display a sum of all offers? The tricky part is: we allow different filters to be applied to the list. these filters should also be applied when calculating the sum. Examples:
Without any filters
| offer name | offer price |
----------------------------
| offer 1 | $1000
| offer 2 | $2000
| offer 3 | $5000
----------------------------
| | $8000 total
Without any filters
| offer name | offer price |
----------------------------
| offer 1 | $1000
| offer 2 | $2000
| offer 3 | $5000
----------------------------
| | $8000 total
With filter name: ilike "%2%"
| offer name | offer price |
----------------------------
| offer 2 | $2000
----------------------------
| | $2000 total
With filter name: ilike "%2%"
| offer name | offer price |
----------------------------
| offer 2 | $2000
----------------------------
| | $2000 total
So, I'm thinking of something like:
offersAggregate(filter: OfferFilterInput) {
price
}
offersAggregate(filter: OfferFilterInput) {
price
}
IMHO, the important part is to accept the same OfferFilterInput as the offers-list query, which would then reduce a lot of additional code on our side. Perhaps there's already something like this available and I'm simply finding it. What would be the best way? I already asked Gemini but it lied to me 😂 Thanks a lot in advance!
2 Replies
ZachDaniel
ZachDaniel4mo ago
So you could write a generic action that does this You could have an argument called filter that is a map and use argument_input_types' to specify that the input type is the filter type name Pass that into Ash.Query.filter_input and Ash.sum`
lukasender
lukasenderOP4mo ago
Ok, nice! I'll try that Seems to work in the first test! 😁

Did you find this page helpful?