You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/pages/en/developing/creating-a-subgraph.mdx
+62
Original file line number
Diff line number
Diff line change
@@ -1298,3 +1298,65 @@ Handlers for File Data Sources cannot be in files which import `eth_call` contra
1298
1298
#### References
1299
1299
1300
1300
[GIP File Data Sources](https://forum.thegraph.com/t/gip-file-data-sources/2721)
1301
+
1302
+
## Timeseries and Aggregations
1303
+
1304
+
### Overview
1305
+
1306
+
Timeseries and aggregations enable your subgraph to track statistics like daily average price, hourly total transfers, etc.
1307
+
1308
+
This feature introduces two new types of subgraph entity. Timeseries entities record data points with timestamps. Aggregation entities perform pre-declared calculations on the Timeseries data points on an hourly or daily basis, then store the results for easy access via GraphQL.
1309
+
1310
+
#### Example Schema
1311
+
1312
+
```graphql
1313
+
type Data @entity(timeseries: true) {
1314
+
id: Int8!
1315
+
timestamp: Timestamp!
1316
+
price: BigDecimal!
1317
+
}
1318
+
1319
+
type Stats @aggregation(intervals: ["hour", "day"], source: "Data") {
Timeseries entities are defined with `@entity(timeseries: true)` in schema.graphql. Every timeseries entity must have a unique ID of the int8 type, a timestamp of the Timestamp type, and include data that will be used for calculation by aggregation entities. These Timeseries entities can be saved in regular trigger handlers, and act as the “raw data” for the Aggregation entities.
1329
+
1330
+
Aggregation entities are defined with `@aggregation` in schema.graphql. Every aggregation entity defines the source from which it will gather data (which must be a Timeseries entity), sets the intervals (e.g., hour, day), and specifies the aggregation function it will use (e.g., sum, count, min, max, first, last). Aggregation entities are automatically calculated on the basis of the specified source at the end of the required interval.
1331
+
1332
+
#### Available Aggregation Intervals
1333
+
1334
+
- `hour`: sets the timeseries period every hour, on the hour.
1335
+
- `day`: sets the timeseries period every day, starting and ending at 00:00.
To use Timeseries and Aggregations, a subgraph must have a spec version ≥1.1.0. Note that this feature might undergo significant changes that could affect backward compatibility.
1361
+
1362
+
[Read more](https://github.com/graphprotocol/graph-node/blob/master/docs/aggregations.md) about Timeseries and Aggregations.
0 commit comments