Ash FrameworkAF
Ash Frameworkโ€ข7mo agoโ€ข
6 replies
lukasender

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


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



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
}


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!
Was this page helpful?