graphile / graphile/pg-aggregates

Support aggregate filters

Open
#78 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
89
Forks
19
PR merge metrics
No merged PRs in 30d

Description

### Feature description

Ideally I would there to be a way to have different filters for different aggregates in the same query, so something like the following example SQL can be generated:

```
SELECT
conv_date AS date,
COUNT(*) FILTER (WHERE visitor_status = 'new') AS new_count,
SUM(revenue) FILTER (WHERE visitor_status = 'new') AS new_revenue,
COUNT(*) FILTER (WHERE visitor_status = 'returning') AS returning_count,
SUM(revenue) FILTER (WHERE visitor_status = 'returning') AS returning_revenue
FROM picked
WHERE someother_condition = 1
GROUP BY conv_date
ORDER BY conv_date;
```

I'm not sure what's the best way for the GraphQL to look like to generate this kind of queries.

This doesn't have to be added out of the box, but rather could be provided as custom function or something similar to defining our own aggreations.
I asked about this and [was suggested to post here](https://discord.com/channels/489127045289476126/1419364005784326175).

### Motivating example

We do many aggregations in our frontend and generate graphs for them. It's cumbersome to create a view with all possible combinations of filters so would be nice if this query could be natively expressed in GraphQL.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.