Skip to content

Commit 9323111

Browse files
Timeseries and aggregations edits (#865)
* Updates * Minor edits * Fixes
1 parent 7464e75 commit 9323111

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

website/pages/en/subgraphs/developing/creating/advanced.mdx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ dataSources: ...
2929
3030
## Timeseries and Aggregations
3131
32-
Timeseries and aggregations enable your subgraph to track statistics like daily average price, hourly total transfers, etc.
32+
Prerequisites:
3333
34-
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.
34+
- Subgraph specVersion must be ≥1.1.0.
35+
36+
Timeseries and aggregations enable your subgraph to track statistics like daily average price, hourly total transfers, and more.
37+
38+
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.
3539
3640
### Example Schema
3741
@@ -49,11 +53,19 @@ type Stats @aggregation(intervals: ["hour", "day"], source: "Data") {
4953
}
5054
```
5155

52-
### Defining Timeseries and Aggregations
56+
### How to Define Timeseries and Aggregations
57+
58+
Timeseries entities are defined with `@entity(timeseries: true)` in the GraphQL schema. Every timeseries entity must:
59+
60+
- have a unique ID of the int8 type
61+
- have a timestamp of the Timestamp type
62+
- include data that will be used for calculation by aggregation entities.
5363

54-
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.
64+
These Timeseries entities can be saved in regular trigger handlers, and act as the “raw data” for the aggregation entities.
5565

56-
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.
66+
Aggregation entities are defined with `@aggregation` in the GraphQL schema. 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).
67+
68+
Aggregation entities are automatically calculated on the basis of the specified source at the end of the required interval.
5769

5870
#### Available Aggregation Intervals
5971

@@ -81,10 +93,6 @@ Aggregation entities are defined with `@aggregation` in schema.graphql. Every ag
8193
}
8294
```
8395

84-
Note:
85-
86-
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.
87-
8896
[Read more](https://github.com/graphprotocol/graph-node/blob/master/docs/aggregations.md) about Timeseries and Aggregations.
8997

9098
## Non-fatal errors

0 commit comments

Comments
 (0)