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.
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:
So, I'm thinking of something like:
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
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`Ok, nice! I'll try that
Seems to work in the first test! 😁