Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraphQL for Time Series

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?

like image 517
Sibelius Seraphini Avatar asked Mar 07 '17 00:03

Sibelius Seraphini


1 Answers

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?

like image 178
Andrew Ingram Avatar answered Oct 16 '22 14:10

Andrew Ingram