From 7246fbd77479ef923ec601bc9f4cb6f5a720f128 Mon Sep 17 00:00:00 2001 From: Idalith Bustos Date: Fri, 20 Sep 2024 10:02:14 -0700 Subject: [PATCH 1/8] edits --- website/pages/en/developing/graph-ts/api.mdx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/website/pages/en/developing/graph-ts/api.mdx b/website/pages/en/developing/graph-ts/api.mdx index b0547989075e..1a47ffb1699f 100644 --- a/website/pages/en/developing/graph-ts/api.mdx +++ b/website/pages/en/developing/graph-ts/api.mdx @@ -4,12 +4,14 @@ title: AssemblyScript API > Note: if you created a subgraph prior to `graph-cli`/`graph-ts` version `0.22.0`, you're using an older version of AssemblyScript, we recommend taking a look at the [`Migration Guide`](/release-notes/assemblyscript-migration-guide) -This page documents what built-in APIs can be used when writing subgraph mappings. Two kinds of APIs are available out of the box: +Learn what built-in APIs can be used when writing subgraph mappings. There are two kinds of APIs available out of the box: - the [Graph TypeScript library](https://github.com/graphprotocol/graph-tooling/tree/main/packages/ts) (`graph-ts`) and - code generated from subgraph files by `graph codegen`. -It is also possible to add other libraries as dependencies, as long as they are compatible with [AssemblyScript](https://github.com/AssemblyScript/assemblyscript). Since this is the language mappings are written in, the [AssemblyScript wiki](https://github.com/AssemblyScript/assemblyscript/wiki) is a good source for language and standard library features. +You can also add other libraries as dependencies, as long as they are compatible with [AssemblyScript](https://github.com/AssemblyScript/assemblyscript). + +Since language mappings are written in Assembly script, it is useful to review the language and standard library features from the [AssemblyScript wiki](https://github.com/AssemblyScript/assemblyscript/wiki). ## API Reference From 5cff4134ceaf7fa50fda91c84ba251b92993c61c Mon Sep 17 00:00:00 2001 From: Idalith Bustos Date: Fri, 20 Sep 2024 11:10:21 -0700 Subject: [PATCH 2/8] updated --- website/pages/en/developing/graph-ts/api.mdx | 25 +++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/website/pages/en/developing/graph-ts/api.mdx b/website/pages/en/developing/graph-ts/api.mdx index 1a47ffb1699f..a123b591a67a 100644 --- a/website/pages/en/developing/graph-ts/api.mdx +++ b/website/pages/en/developing/graph-ts/api.mdx @@ -2,12 +2,12 @@ title: AssemblyScript API --- -> Note: if you created a subgraph prior to `graph-cli`/`graph-ts` version `0.22.0`, you're using an older version of AssemblyScript, we recommend taking a look at the [`Migration Guide`](/release-notes/assemblyscript-migration-guide) +> Note: If you created a subgraph prior to `graph-cli`/`graph-ts` version `0.22.0`, then you're using an older version of AssemblyScript. It is recommended to review the [`Migration Guide`](/release-notes/assemblyscript-migration-guide) Learn what built-in APIs can be used when writing subgraph mappings. There are two kinds of APIs available out of the box: -- the [Graph TypeScript library](https://github.com/graphprotocol/graph-tooling/tree/main/packages/ts) (`graph-ts`) and -- code generated from subgraph files by `graph codegen`. +- The [Graph TypeScript library](https://github.com/graphprotocol/graph-tooling/tree/main/packages/ts) (`graph-ts`) +- Code generated from subgraph files by `graph codegen`. You can also add other libraries as dependencies, as long as they are compatible with [AssemblyScript](https://github.com/AssemblyScript/assemblyscript). @@ -248,7 +248,9 @@ export function handleTransfer(event: TransferEvent): void { When a `Transfer` event is encountered while processing the chain, it is passed to the `handleTransfer` event handler using the generated `Transfer` type (aliased to `TransferEvent` here to avoid a naming conflict with the entity type). This type allows accessing data such as the event's parent transaction and its parameters. -Each entity must have a unique ID to avoid collisions with other entities. It is fairly common for event parameters to include a unique identifier that can be used. Note: Using the transaction hash as the ID assumes that no other events in the same transaction create entities with this hash as the ID. +Each entity must have a unique ID to avoid collisions with other entities. It is fairly common for event parameters to include a unique identifier that can be used. + +> Note: Using the transaction hash as the ID assumes that no other events in the same transaction create entities with this hash as the ID. #### Loading entities from the store @@ -264,15 +266,18 @@ if (transfer == null) { // Use the Transfer entity as before ``` -As the entity may not exist in the store yet, the `load` method returns a value of type `Transfer | null`. It may thus be necessary to check for the `null` case before using the value. +As the entity may not exist in the store yet, the `load` method returns a value of type `Transfer | null`. It may be necessary to check for the `null` case before using the value. -> **Note:** Loading entities is only necessary if the changes made in the mapping depend on the previous data of an entity. See the next section for the two ways of updating existing entities. +> Note: Loading entities is only necessary if the changes made in the mapping depend on the previous data of an entity. See the next section for the two ways of updating existing entities. #### Looking up entities created withing a block As of `graph-node` v0.31.0, `@graphprotocol/graph-ts` v0.30.0 and `@graphprotocol/graph-cli` v0.49.0 the `loadInBlock` method is available on all entity types. -The store API facilitates the retrieval of entities that were created or updated in the current block. A typical situation for this is that one handler creates a Transaction from some on-chain event, and a later handler wants to access this transaction if it exists. In the case where the transaction does not exist, the subgraph will have to go to the database just to find out that the entity does not exist; if the subgraph author already knows that the entity must have been created in the same block, using loadInBlock avoids this database roundtrip. For some subgraphs, these missed lookups can contribute significantly to the indexing time. +The store API facilitates the retrieval of entities that were created or updated in the current block. A typical situation for this is that one handler creates a Transaction from some on-chain event, and a later handler wants to access this transaction if it exists. + +- In the case where the transaction does not exist, the subgraph will have to go to the database simply to find out that the entity does not exist. If the subgraph author already knows that the entity must have been created in the same block, using loadInBlock avoids this database roundtrip. +- For some subgraphs, these missed lookups can contribute significantly to the indexing time. ```typescript let id = event.transaction.hash // or however the ID is constructed @@ -499,7 +504,9 @@ Any other contract that is part of the subgraph can be imported from the generat #### Handling Reverted Calls -If the read-only methods of your contract may revert, then you should handle that by calling the generated contract method prefixed with `try_`. For example, the Gravity contract exposes the `gravatarToOwner` method. This code would be able to handle a revert in that method: +If the read-only methods of your contract may revert, then you should handle that by calling the generated contract method prefixed with `try_`. + +- For example, the Gravity contract exposes the `gravatarToOwner` method. This code would be able to handle a revert in that method: ```typescript let gravity = Gravity.bind(event.address) @@ -511,7 +518,7 @@ if (callResult.reverted) { } ``` -Note that a Graph node connected to a Geth or Infura client may not detect all reverts, if you rely on this we recommend using a Graph node connected to a Parity client. +> Note: A Graph node connected to a Geth or Infura client may not detect all reverts, if you rely on this we recommend using a Graph node connected to a Parity client. #### Encoding/Decoding ABI From f9bc59b74f1e75c9de1a27bbfc1a22011368873c Mon Sep 17 00:00:00 2001 From: Idalith <126833353+idalithb@users.noreply.github.com> Date: Fri, 20 Sep 2024 12:12:26 -0700 Subject: [PATCH 3/8] Update website/pages/en/developing/graph-ts/api.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Benoît Rouleau --- website/pages/en/developing/graph-ts/api.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/pages/en/developing/graph-ts/api.mdx b/website/pages/en/developing/graph-ts/api.mdx index a123b591a67a..2868052bb192 100644 --- a/website/pages/en/developing/graph-ts/api.mdx +++ b/website/pages/en/developing/graph-ts/api.mdx @@ -2,7 +2,7 @@ title: AssemblyScript API --- -> Note: If you created a subgraph prior to `graph-cli`/`graph-ts` version `0.22.0`, then you're using an older version of AssemblyScript. It is recommended to review the [`Migration Guide`](/release-notes/assemblyscript-migration-guide) +> Note: If you created a subgraph prior to `graph-cli`/`graph-ts` version `0.22.0`, then you're using an older version of AssemblyScript. It is recommended to review the [`Migration Guide`](/release-notes/assemblyscript-migration-guide). Learn what built-in APIs can be used when writing subgraph mappings. There are two kinds of APIs available out of the box: From 0952bff5ceab0d501e554591e3f3036850edafb6 Mon Sep 17 00:00:00 2001 From: Idalith <126833353+idalithb@users.noreply.github.com> Date: Fri, 20 Sep 2024 12:12:33 -0700 Subject: [PATCH 4/8] Update website/pages/en/developing/graph-ts/api.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Benoît Rouleau --- website/pages/en/developing/graph-ts/api.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/pages/en/developing/graph-ts/api.mdx b/website/pages/en/developing/graph-ts/api.mdx index 2868052bb192..5ab10bef2fec 100644 --- a/website/pages/en/developing/graph-ts/api.mdx +++ b/website/pages/en/developing/graph-ts/api.mdx @@ -11,7 +11,7 @@ Learn what built-in APIs can be used when writing subgraph mappings. There are t You can also add other libraries as dependencies, as long as they are compatible with [AssemblyScript](https://github.com/AssemblyScript/assemblyscript). -Since language mappings are written in Assembly script, it is useful to review the language and standard library features from the [AssemblyScript wiki](https://github.com/AssemblyScript/assemblyscript/wiki). +Since language mappings are written in AssemblyScript, it is useful to review the language and standard library features from the [AssemblyScript wiki](https://github.com/AssemblyScript/assemblyscript/wiki). ## API Reference From 8485005448297dc3d652fde44e440d87bfcb84fa Mon Sep 17 00:00:00 2001 From: Idalith <126833353+idalithb@users.noreply.github.com> Date: Fri, 20 Sep 2024 12:12:43 -0700 Subject: [PATCH 5/8] Update website/pages/en/developing/graph-ts/api.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Benoît Rouleau --- website/pages/en/developing/graph-ts/api.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/pages/en/developing/graph-ts/api.mdx b/website/pages/en/developing/graph-ts/api.mdx index 5ab10bef2fec..45af162d145c 100644 --- a/website/pages/en/developing/graph-ts/api.mdx +++ b/website/pages/en/developing/graph-ts/api.mdx @@ -7,7 +7,7 @@ title: AssemblyScript API Learn what built-in APIs can be used when writing subgraph mappings. There are two kinds of APIs available out of the box: - The [Graph TypeScript library](https://github.com/graphprotocol/graph-tooling/tree/main/packages/ts) (`graph-ts`) -- Code generated from subgraph files by `graph codegen`. +- Code generated from subgraph files by `graph codegen` You can also add other libraries as dependencies, as long as they are compatible with [AssemblyScript](https://github.com/AssemblyScript/assemblyscript). From 681e8f7c84a4dc7828f0633c1c704bd3dd4c2d0b Mon Sep 17 00:00:00 2001 From: Idalith <126833353+idalithb@users.noreply.github.com> Date: Fri, 20 Sep 2024 12:12:50 -0700 Subject: [PATCH 6/8] Update website/pages/en/developing/graph-ts/api.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Benoît Rouleau --- website/pages/en/developing/graph-ts/api.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/pages/en/developing/graph-ts/api.mdx b/website/pages/en/developing/graph-ts/api.mdx index 45af162d145c..884aff18700d 100644 --- a/website/pages/en/developing/graph-ts/api.mdx +++ b/website/pages/en/developing/graph-ts/api.mdx @@ -274,7 +274,7 @@ As the entity may not exist in the store yet, the `load` method returns a value As of `graph-node` v0.31.0, `@graphprotocol/graph-ts` v0.30.0 and `@graphprotocol/graph-cli` v0.49.0 the `loadInBlock` method is available on all entity types. -The store API facilitates the retrieval of entities that were created or updated in the current block. A typical situation for this is that one handler creates a Transaction from some on-chain event, and a later handler wants to access this transaction if it exists. +The store API facilitates the retrieval of entities that were created or updated in the current block. A typical situation for this is that one handler creates a transaction from some on-chain event, and a later handler wants to access this transaction if it exists. - In the case where the transaction does not exist, the subgraph will have to go to the database simply to find out that the entity does not exist. If the subgraph author already knows that the entity must have been created in the same block, using loadInBlock avoids this database roundtrip. - For some subgraphs, these missed lookups can contribute significantly to the indexing time. From 83ce697150a57d6aea0aba3df3cb1f1d68958108 Mon Sep 17 00:00:00 2001 From: Idalith <126833353+idalithb@users.noreply.github.com> Date: Fri, 20 Sep 2024 12:12:57 -0700 Subject: [PATCH 7/8] Update website/pages/en/developing/graph-ts/api.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Benoît Rouleau --- website/pages/en/developing/graph-ts/api.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/pages/en/developing/graph-ts/api.mdx b/website/pages/en/developing/graph-ts/api.mdx index 884aff18700d..fe739a7ab951 100644 --- a/website/pages/en/developing/graph-ts/api.mdx +++ b/website/pages/en/developing/graph-ts/api.mdx @@ -276,7 +276,7 @@ As of `graph-node` v0.31.0, `@graphprotocol/graph-ts` v0.30.0 and `@graphprotoco The store API facilitates the retrieval of entities that were created or updated in the current block. A typical situation for this is that one handler creates a transaction from some on-chain event, and a later handler wants to access this transaction if it exists. -- In the case where the transaction does not exist, the subgraph will have to go to the database simply to find out that the entity does not exist. If the subgraph author already knows that the entity must have been created in the same block, using loadInBlock avoids this database roundtrip. +- In the case where the transaction does not exist, the subgraph will have to go to the database simply to find out that the entity does not exist. If the subgraph author already knows that the entity must have been created in the same block, using `loadInBlock` avoids this database roundtrip. - For some subgraphs, these missed lookups can contribute significantly to the indexing time. ```typescript From 6f43fc333bfff21d4571fd4302ef6305d0f9a547 Mon Sep 17 00:00:00 2001 From: Idalith <126833353+idalithb@users.noreply.github.com> Date: Fri, 20 Sep 2024 12:13:08 -0700 Subject: [PATCH 8/8] Update website/pages/en/developing/graph-ts/api.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Benoît Rouleau --- website/pages/en/developing/graph-ts/api.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/pages/en/developing/graph-ts/api.mdx b/website/pages/en/developing/graph-ts/api.mdx index fe739a7ab951..55630c71a167 100644 --- a/website/pages/en/developing/graph-ts/api.mdx +++ b/website/pages/en/developing/graph-ts/api.mdx @@ -518,7 +518,7 @@ if (callResult.reverted) { } ``` -> Note: A Graph node connected to a Geth or Infura client may not detect all reverts, if you rely on this we recommend using a Graph node connected to a Parity client. +> Note: A Graph node connected to a Geth or Infura client may not detect all reverts. If you rely on this, we recommend using a Graph Node connected to a Parity client. #### Encoding/Decoding ABI