Skip to content

Commit 21cb3ff

Browse files
committed
updating edits
1 parent 0b1e690 commit 21cb3ff

File tree

4 files changed

+128
-18
lines changed

4 files changed

+128
-18
lines changed

website/pages/en/developing/creating-a-subgraph/advanced.mdx

Lines changed: 117 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
title: Advance Subgraph Features
33
---
44

5-
## Experimental features
5+
## Overview
6+
7+
Learn about and implement advanced subgraph features to enhanced your subgraph's built.
68

79
Starting from `specVersion` `0.0.4`, subgraph features must be explicitly declared in the `features` section at the top level of the manifest file, using their `camelCase` name, as listed in the table below:
810

@@ -23,7 +25,115 @@ features:
2325
dataSources: ...
2426
```
2527
26-
Note that using a feature without declaring it will incur a **validation error** during subgraph deployment, but no errors will occur if a feature is declared but not used.
28+
> Note that using a feature without declaring it will incur a **validation error** during subgraph deployment, but no errors will occur if a feature is declared but not used.
29+
30+
## Timeseries and Aggregations
31+
32+
Timeseries and aggregations enable your subgraph to track statistics like daily average price, hourly total transfers, etc.
33+
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.
35+
36+
### Example Schema
37+
38+
```graphql
39+
type Data @entity(timeseries: true) {
40+
id: Int8!
41+
timestamp: Timestamp!
42+
price: BigDecimal!
43+
}
44+
45+
type Stats @aggregation(intervals: ["hour", "day"], source: "Data") {
46+
id: Int8!
47+
timestamp: Timestamp!
48+
sum: BigDecimal! @aggregate(fn: "sum", arg: "price")
49+
}
50+
```
51+
52+
### Defining Timeseries and Aggregations
53+
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.
55+
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.
57+
58+
#### Available Aggregation Intervals
59+
60+
- `hour`: sets the timeseries period every hour, on the hour.
61+
- `day`: sets the timeseries period every day, starting and ending at 00:00.
62+
63+
#### Available Aggregation Functions
64+
65+
- `sum`: Total of all values.
66+
- `count`: Number of values.
67+
- `min`: Minimum value.
68+
- `max`: Maximum value.
69+
- `first`: First value in the period.
70+
- `last`: Last value in the period.
71+
72+
#### Example Aggregations Query
73+
74+
```graphql
75+
{
76+
stats(interval: "hour", where: { timestamp_gt: 1704085200 }) {
77+
id
78+
timestamp
79+
sum
80+
}
81+
}
82+
```
83+
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+
88+
[Read more](https://github.com/graphprotocol/graph-node/blob/master/docs/aggregations.md) about Timeseries and Aggregations.
89+
90+
## Non-fatal errors
91+
92+
Indexing errors on already synced subgraphs will, by default, cause the subgraph to fail and stop syncing. Subgraphs can alternatively be configured to continue syncing in the presence of errors, by ignoring the changes made by the handler which provoked the error. This gives subgraph authors time to correct their subgraphs while queries continue to be served against the latest block, though the results might be inconsistent due to the bug that caused the error. Note that some errors are still always fatal. To be non-fatal, the error must be known to be deterministic.
93+
94+
> **Note:** The Graph Network does not yet support non-fatal errors, and developers should not deploy subgraphs using that functionality to the network via the Studio.
95+
96+
Enabling non-fatal errors requires setting the following feature flag on the subgraph manifest:
97+
98+
```yaml
99+
specVersion: 0.0.4
100+
description: Gravatar for Ethereum
101+
features:
102+
- nonFatalErrors
103+
...
104+
```
105+
106+
The query must also opt-in to querying data with potential inconsistencies through the `subgraphError` argument. It is also recommended to query `_meta` to check if the subgraph has skipped over errors, as in the example:
107+
108+
```graphql
109+
foos(first: 100, subgraphError: allow) {
110+
id
111+
}
112+
113+
_meta {
114+
hasIndexingErrors
115+
}
116+
```
117+
118+
If the subgraph encounters an error, that query will return both the data and a graphql error with the message `"indexing_error"`, as in this example response:
119+
120+
```graphql
121+
"data": {
122+
"foos": [
123+
{
124+
"id": "0xdead"
125+
}
126+
],
127+
"_meta": {
128+
"hasIndexingErrors": true
129+
}
130+
},
131+
"errors": [
132+
{
133+
"message": "indexing_error"
134+
}
135+
]
136+
```
27137

28138
## IPFS/Arweave File Data Sources
29139

@@ -243,7 +353,7 @@ Handlers for File Data Sources cannot be in files which import `eth_call` contra
243353

244354
[GIP File Data Sources](https://forum.thegraph.com/t/gip-file-data-sources/2721)
245355

246-
### Indexed Argument Filters / Topic Filters
356+
## Indexed Argument Filters / Topic Filters
247357

248358
> **Requires**: [SpecVersion](#specversion-releases) >= `1.2.0`
249359
@@ -253,7 +363,7 @@ Topic filters, also known as indexed argument filters, are a powerful feature in
253363

254364
- This is useful for creating personal subgraphs that track specific addresses and their interactions with various smart contracts on the blockchain.
255365

256-
#### How Topic Filters Work
366+
### How Topic Filters Work
257367

258368
When a smart contract emits an event, any arguments that are marked as indexed can be used as filters in a subgraph's manifest. This allows the subgraph to listen selectively for events that match these indexed arguments.
259369

@@ -299,7 +409,7 @@ In this setup:
299409
- `topic1` corresponds to the first indexed argument of the event, `topic2` to the second, and `topic3` to the third.
300410
- Each topic can have one or more values, and an event is only processed if it matches one of the values in each specified topic.
301411

302-
##### Filter Logic
412+
#### Filter Logic
303413

304414
- Within a Single Topic: The logic functions as an OR condition. The event will be processed if it matches any one of the listed values in a given topic.
305415
- Between Different Topics: The logic functions as an AND condition. An event must satisfy all specified conditions across different topics to trigger the associated handler.
@@ -336,7 +446,7 @@ In this configuration:
336446
- `topic2` is configured to filter `Transfer` events where `0xAddressB` and `0xAddressC` is the receiver.
337447
- The subgraph will index transactions that occur in either direction between multiple addresses allowing for comprehensive monitoring of interactions involving all addresses.
338448

339-
### Declared eth_call
449+
## Declared eth_call
340450

341451
> Note: This is an experimental feature that is not currently available in a stable Graph Node release yet. You can only use it in Subgraph Studio or your self-hosted node.
342452

@@ -348,7 +458,7 @@ This feature does the following:
348458
- Allows faster data fetching, resulting in quicker query responses and a better user experience.
349459
- Reduces wait times for applications that need to aggregate data from multiple Ethereum calls, making the data retrieval process more efficient.
350460

351-
#### Key Concepts
461+
### Key Concepts
352462

353463
- Declarative `eth_calls`: Ethereum calls that are defined to be executed in parallel rather than sequentially.
354464
- Parallel Execution: Instead of waiting for one call to finish before starting the next, multiple calls can be initiated simultaneously.

website/pages/en/developing/creating-a-subgraph/install-the-cli.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Install the Graph CLI
33
---
44

5-
> In order to use your subgraph on The Graph's decentralized network, you will need to [create an API key](/deploying/subgraph-studio-faqs/#2-how-do-i-create-an-api-key) in [Subgraph Studio](https://thegraph.com/studio/apikeys/). It is recommended that you add signal to your subgraph with at least 3,000 GRT to attract 2-3 Indexers.
5+
> In order to use your subgraph on The Graph's decentralized network, you will need to [create an API key](/deploying/subgraph-studio-faqs/#2-how-do-i-create-an-api-key) in [Subgraph Studio](https://thegraph.com/studio/apikeys/). It is recommended that you add signal to your subgraph with at least 3,000 GRT to attract 2-3 Indexers. To learn more about signaling, check out [curating](/network/curating/).
66
77
## Getting Started
88

@@ -96,15 +96,15 @@ The `graph add` command will fetch the ABI from Etherscan (unless an ABI path is
9696

9797
> Note: When using the interactive CLI, after successfully running `graph init`, you'll be prompted to add a new `dataSource`.
9898
99-
## Getting The ABIs
99+
### Getting The ABIs
100100

101101
The ABI file(s) must match your contract(s). There are a few ways to obtain ABI files:
102102

103103
- If you are building your own project, you will likely have access to your most current ABIs.
104104
- If you are building a subgraph for a public project, you can download that project to your computer and get the ABI by using [`npx hardhat compile`](https://hardhat.org/hardhat-runner/docs/guides/compile-contracts#compiling-your-contracts) or using `solc` to compile.
105105
- You can also find the ABI on [Etherscan](https://etherscan.io/), but this isn't always reliable, as the ABI that is uploaded there may be out of date. Make sure you have the right ABI, otherwise running your subgraph will fail.
106106

107-
### SpecVersion Releases
107+
## SpecVersion Releases
108108

109109
| Version | Release notes |
110110
| :-: | --- |

website/pages/en/developing/creating-a-subgraph/ql-schema.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ The following scalars are supported in the GraphQL API:
8383
| `BigDecimal` | `BigDecimal` High precision decimals represented as a significand and an exponent. The exponent range is from −6143 to +6144. Rounded to 34 significant digits. |
8484
| `Timestamp` | It is an `i64` value in microseconds. Commonly used for `timestamp` fields for timeseries and aggregations. |
8585

86-
#### Enums
86+
### Enums
8787

8888
You can also create enums within a schema. Enums have the following syntax:
8989

@@ -99,7 +99,7 @@ Once the enum is defined in the schema, you can use the string representation of
9999

100100
More detail on writing enums can be found in the [GraphQL documentation](https://graphql.org/learn/schema/).
101101

102-
#### Entity Relationships
102+
### Entity Relationships
103103

104104
An entity may have a relationship to one or more other entities in your schema. These relationships may be traversed in your queries. Relationships in The Graph are unidirectional. It is possible to simulate bidirectional relationships by defining a unidirectional relationship on either "end" of the relationship.
105105

@@ -137,7 +137,7 @@ type TokenBalance @entity {
137137
}
138138
```
139139

140-
#### Reverse Lookups
140+
### Reverse Lookups
141141

142142
Reverse lookups can be defined on an entity through the `@derivedFrom` field. This creates a virtual field on the entity that may be queried but cannot be set manually through the mappings API. Rather, it is derived from the relationship defined on the other entity. For such relationships, it rarely makes sense to store both sides of the relationship, and both indexing and query performance will be better when only one side is stored and the other is derived.
143143

@@ -221,7 +221,7 @@ query usersWithOrganizations {
221221

222222
This more elaborate way of storing many-to-many relationships will result in less data stored for the subgraph, and therefore to a subgraph that is often dramatically faster to index and to query.
223223

224-
#### Adding comments to the schema
224+
### Adding comments to the schema
225225

226226
As per GraphQL spec, comments can be added above schema entity attributes using the hash symbol `#`. This is illustrated in the example below:
227227

@@ -277,7 +277,7 @@ query {
277277

278278
> **[Feature Management](#experimental-features):** From `specVersion` `0.0.4` and onwards, `fullTextSearch` must be declared under the `features` section in the subgraph manifest.
279279
280-
### Languages supported
280+
## Languages supported
281281

282282
Choosing a different language will have a definitive, though sometimes subtle, effect on the fulltext search API. Fields covered by a fulltext query field are examined in the context of the chosen language, so the lexemes produced by analysis and search queries vary from language to language. For example: when using the supported Turkish dictionary "token" is stemmed to "toke" while, of course, the English dictionary will stem it to "token".
283283

website/pages/en/developing/creating-a-subgraph/subgraph-manifest.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ The **subgraph definition** consists of the following files:
1414

1515
- `mapping.ts`: [AssemblyScript Mappings](https://github.com/AssemblyScript/assemblyscript) code that translates event data into entities defined in your schema (e.g. `mapping.ts` in this guide)
1616

17-
> Note: Please make sure you populate your subgraph manifest with both entities and add all handlers.
18-
1917
### Subgraph Capabilities
2018

2119
A single subgraph can:
@@ -81,6 +79,8 @@ dataSources:
8179
8280
## Subgraph Entries
8381
82+
> Important Note: Be sure you populate your subgraph manifest with all handlers and [entities](/developing/creating-a-subgraph/ql-schema/).
83+
8484
The important entries to update for the manifest are:
8585
8686
- `specVersion`: a semver version that identifies the supported manifest structure and functionality for the subgraph. The latest version is `1.2.0`. See [specVersion releases](#specversion-releases) section to see more details on features & releases.
@@ -328,7 +328,7 @@ eventHandlers:
328328

329329
Inside the handler function, the receipt can be accessed in the `Event.receipt` field. When the `receipt` key is set to `false` or omitted in the manifest, a `null` value will be returned instead.
330330

331-
### Order of Triggering Handlers
331+
## Order of Triggering Handlers
332332

333333
The triggers for a data source within a block are ordered using the following process:
334334

0 commit comments

Comments
 (0)