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/advanced.mdx
+117-7Lines changed: 117 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,9 @@
2
2
title: Advance Subgraph Features
3
3
---
4
4
5
-
## Experimental features
5
+
## Overview
6
+
7
+
Learn about and implement advanced subgraph features to enhanced your subgraph's built.
6
8
7
9
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:
8
10
@@ -23,7 +25,115 @@ features:
23
25
dataSources: ...
24
26
```
25
27
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") {
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.
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
+
```
27
137
28
138
## IPFS/Arweave File Data Sources
29
139
@@ -243,7 +353,7 @@ Handlers for File Data Sources cannot be in files which import `eth_call` contra
243
353
244
354
[GIP File Data Sources](https://forum.thegraph.com/t/gip-file-data-sources/2721)
@@ -253,7 +363,7 @@ Topic filters, also known as indexed argument filters, are a powerful feature in
253
363
254
364
- This is useful for creating personal subgraphs that track specific addresses and their interactions with various smart contracts on the blockchain.
255
365
256
-
#### How Topic Filters Work
366
+
### How Topic Filters Work
257
367
258
368
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.
259
369
@@ -299,7 +409,7 @@ In this setup:
299
409
- `topic1` corresponds to the first indexed argument of the event, `topic2` to the second, and `topic3` to the third.
300
410
- 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.
301
411
302
-
##### Filter Logic
412
+
#### Filter Logic
303
413
304
414
- 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.
305
415
- 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:
336
446
- `topic2`is configured to filter `Transfer` events where `0xAddressB` and `0xAddressC` is the receiver.
337
447
- The subgraph will index transactions that occur in either direction between multiple addresses allowing for comprehensive monitoring of interactions involving all addresses.
338
448
339
-
### Declared eth_call
449
+
## Declared eth_call
340
450
341
451
> 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.
342
452
@@ -348,7 +458,7 @@ This feature does the following:
348
458
- Allows faster data fetching, resulting in quicker query responses and a better user experience.
349
459
- Reduces wait times for applications that need to aggregate data from multiple Ethereum calls, making the data retrieval process more efficient.
350
460
351
-
#### Key Concepts
461
+
### Key Concepts
352
462
353
463
- Declarative `eth_calls`: Ethereum calls that are defined to be executed in parallel rather than sequentially.
354
464
- Parallel Execution: Instead of waiting for one call to finish before starting the next, multiple calls can be initiated simultaneously.
Copy file name to clipboardExpand all lines: website/pages/en/developing/creating-a-subgraph/install-the-cli.mdx
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: Install the Graph CLI
3
3
---
4
4
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/).
6
6
7
7
## Getting Started
8
8
@@ -96,15 +96,15 @@ The `graph add` command will fetch the ABI from Etherscan (unless an ABI path is
96
96
97
97
> Note: When using the interactive CLI, after successfully running `graph init`, you'll be prompted to add a new `dataSource`.
98
98
99
-
## Getting The ABIs
99
+
###Getting The ABIs
100
100
101
101
The ABI file(s) must match your contract(s). There are a few ways to obtain ABI files:
102
102
103
103
- If you are building your own project, you will likely have access to your most current ABIs.
104
104
- 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.
105
105
- 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.
Copy file name to clipboardExpand all lines: website/pages/en/developing/creating-a-subgraph/ql-schema.mdx
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,7 +83,7 @@ The following scalars are supported in the GraphQL API:
83
83
| `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. |
84
84
| `Timestamp` | It is an `i64` value in microseconds. Commonly used for `timestamp` fields for timeseries and aggregations. |
85
85
86
-
#### Enums
86
+
### Enums
87
87
88
88
You can also create enums within a schema. Enums have the following syntax:
89
89
@@ -99,7 +99,7 @@ Once the enum is defined in the schema, you can use the string representation of
99
99
100
100
More detail on writing enums can be found in the [GraphQL documentation](https://graphql.org/learn/schema/).
101
101
102
-
####Entity Relationships
102
+
### Entity Relationships
103
103
104
104
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.
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.
223
223
224
-
####Adding comments to the schema
224
+
### Adding comments to the schema
225
225
226
226
As per GraphQL spec, comments can be added above schema entity attributes using the hash symbol `#`. This is illustrated in the example below:
227
227
@@ -277,7 +277,7 @@ query {
277
277
278
278
> **[Feature Management](#experimental-features):** From `specVersion``0.0.4` and onwards, `fullTextSearch` must be declared under the `features` section in the subgraph manifest.
279
279
280
-
###Languages supported
280
+
## Languages supported
281
281
282
282
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".
Copy file name to clipboardExpand all lines: website/pages/en/developing/creating-a-subgraph/subgraph-manifest.mdx
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,8 +14,6 @@ The **subgraph definition** consists of the following files:
14
14
15
15
-`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)
16
16
17
-
> Note: Please make sure you populate your subgraph manifest with both entities and add all handlers.
18
-
19
17
### Subgraph Capabilities
20
18
21
19
A single subgraph can:
@@ -81,6 +79,8 @@ dataSources:
81
79
82
80
## Subgraph Entries
83
81
82
+
> Important Note: Be sure you populate your subgraph manifest with all handlers and [entities](/developing/creating-a-subgraph/ql-schema/).
83
+
84
84
The important entries to update for the manifest are:
85
85
86
86
- `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:
328
328
329
329
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.
330
330
331
-
### Order of Triggering Handlers
331
+
## Order of Triggering Handlers
332
332
333
333
The triggers for a data source within a block are ordered using the following process:
0 commit comments