graphprotocol / graph-node

Graph Node indexes data from blockchains such as Ethereum and serves it over GraphQL
https://thegraph.com
Apache License 2.0
2.85k stars 930 forks source link

[Feature] Windowed aggregates #5302

Open lutter opened 3 months ago

lutter commented 3 months ago

Description

Aggregates can be formed either over the current bucket (hour, day) or the entire lifetime of the underlying timeseries. In some cases, it would also be useful to aggregate over a limited window, e.g., the last 6 hours. That could look something like

  recent_max_price: BigDecimal! @aggregate(fn: "max", arg: "price", window: 6)

The current ways to aggregate would be expressed as window: 1 (default) and window: "all" (lifetime/cumulative)

There's a bunch of things that aren't entirely clear:

azf20 commented 2 months ago

@lutter do you imagine this being updated on every block, or on the hour?

lutter commented 2 months ago

@azf20 It would still only be updated on the hour/day, but would consider data reaching farther back than just that interval