From 2091e54c3030e8714dd19e0a4a3efdaba059ccf9 Mon Sep 17 00:00:00 2001 From: Michael Macaulay Date: Wed, 29 Jan 2025 16:22:05 -0500 Subject: [PATCH 1/3] Updates --- .../developing/creating/advanced.mdx | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/website/pages/en/subgraphs/developing/creating/advanced.mdx b/website/pages/en/subgraphs/developing/creating/advanced.mdx index 3296b94335e6..52534227a999 100644 --- a/website/pages/en/subgraphs/developing/creating/advanced.mdx +++ b/website/pages/en/subgraphs/developing/creating/advanced.mdx @@ -29,6 +29,10 @@ dataSources: ... ## Timeseries and Aggregations +Prerequisites: + +- Subgraph specVersion must be ≥1.1.0. + Timeseries and aggregations enable your subgraph to track statistics like daily average price, hourly total transfers, etc. 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. @@ -49,11 +53,18 @@ type Stats @aggregation(intervals: ["hour", "day"], source: "Data") { } ``` -### Defining Timeseries and Aggregations +### How to Define Timeseries and Aggregations + +Timeseries entities are defined with `@entity(timeseries: true)` in the GraphQL schema. Every timeseries entity must: +- have a unique ID of the int8 type +- have a timestamp of the Timestamp type +- include data that will be used for calculation by aggregation entities. -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. +These Timeseries entities can be saved in regular trigger handlers, and act as the “raw data” for the aggregation entities. -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. +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). + +Aggregation entities are automatically calculated on the basis of the specified source at the end of the required interval. #### Available Aggregation Intervals @@ -81,10 +92,6 @@ Aggregation entities are defined with `@aggregation` in schema.graphql. Every ag } ``` -Note: - -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. - [Read more](https://github.com/graphprotocol/graph-node/blob/master/docs/aggregations.md) about Timeseries and Aggregations. ## Non-fatal errors From f325cd49128f32eb9db2036dcc89905216a4d67c Mon Sep 17 00:00:00 2001 From: Michael Macaulay Date: Wed, 29 Jan 2025 16:22:57 -0500 Subject: [PATCH 2/3] Minor edits --- website/pages/en/subgraphs/developing/creating/advanced.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/pages/en/subgraphs/developing/creating/advanced.mdx b/website/pages/en/subgraphs/developing/creating/advanced.mdx index 52534227a999..5ac1fdd3af24 100644 --- a/website/pages/en/subgraphs/developing/creating/advanced.mdx +++ b/website/pages/en/subgraphs/developing/creating/advanced.mdx @@ -33,9 +33,9 @@ Prerequisites: - Subgraph specVersion must be ≥1.1.0. -Timeseries and aggregations enable your subgraph to track statistics like daily average price, hourly total transfers, etc. +Timeseries and aggregations enable your subgraph to track statistics like daily average price, hourly total transfers, and more. -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. +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. ### Example Schema From c90e002d62491141f3f314dc58d43001cac3e151 Mon Sep 17 00:00:00 2001 From: Michael Macaulay Date: Wed, 29 Jan 2025 16:44:16 -0500 Subject: [PATCH 3/3] Fixes --- website/pages/en/subgraphs/developing/creating/advanced.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/website/pages/en/subgraphs/developing/creating/advanced.mdx b/website/pages/en/subgraphs/developing/creating/advanced.mdx index 5ac1fdd3af24..14f8e608abdf 100644 --- a/website/pages/en/subgraphs/developing/creating/advanced.mdx +++ b/website/pages/en/subgraphs/developing/creating/advanced.mdx @@ -56,6 +56,7 @@ type Stats @aggregation(intervals: ["hour", "day"], source: "Data") { ### How to Define Timeseries and Aggregations Timeseries entities are defined with `@entity(timeseries: true)` in the GraphQL schema. Every timeseries entity must: + - have a unique ID of the int8 type - have a timestamp of the Timestamp type - include data that will be used for calculation by aggregation entities.