Based on this talk: https://www.youtube.com/watch?v=srfaKA2wJ0s
I would like to implement an analytics/time series query in GraphQL like
query {
sales(date: { start: ‘2017-01-01’, end: ‘2018-01-01’ }) {
revenue(stat: mean)
daily: interval(by: day) {
date
revenue
}
}
}
revenue(stat: mean) is an aggregation based on one statistic (mean in this case) daily is a list of data points by hour/day/month
How to implement this using mongodb, or postgresql/mysql databases in a performant way?
Having given this a bit more thought...
I'd have sales(date: { start: ‘2017-01-01’, end: ‘2018-01-01’ })
resolve to an object that looks like this:
{
__type: 'SalesDateSelection',
start: ‘2017-01-01’,
end: '2018-01-01',
}
This is free because it's just a dumb object that holds the arguments it was created with, no expensive data access going on here.
Each of the child fields (revenue(stat: mean)
and interval(by: day)
) can then be resolved using a combination of their arguments and the data on this parent object. Which would presumably be 2 database queries?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With