Skip to content

Commit 0bc6510

Browse files
authored
Add docs for DataSourceContext in manifest (#520)
1 parent e8dedc3 commit 0bc6510

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

website/pages/en/developing/assemblyscript-api.mdx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,61 @@ The base `Entity` class and the child `DataSourceContext` class have helpers to
808808
- `getBoolean(key: string): boolean`
809809
- `getBigDecimal(key: string): BigDecimal`
810810

811+
### DataSourceContext in Manifest
812+
813+
The `context` section within `dataSources` allows you to define key-value pairs that are accessible within your subgraph mappings. The available types are `Bool`, `String`, `Int`, `Int8`, `BigDecimal`, `Bytes`, `List`, and `BigInt`.
814+
815+
Here is a YAML example illustrating the usage of various types in the `context` section:
816+
817+
```yaml
818+
dataSources:
819+
- kind: ethereum/contract
820+
name: ContractName
821+
network: mainnet
822+
context:
823+
bool_example:
824+
type: Bool
825+
data: true
826+
string_example:
827+
type: String
828+
data: 'hello'
829+
int_example:
830+
type: Int
831+
data: 42
832+
int8_example:
833+
type: Int8
834+
data: 127
835+
big_decimal_example:
836+
type: BigDecimal
837+
data: '10.99'
838+
bytes_example:
839+
type: Bytes
840+
data: '0x68656c6c6f'
841+
list_example:
842+
type: List
843+
data:
844+
- type: Int
845+
data: 1
846+
- type: Int
847+
data: 2
848+
- type: Int
849+
data: 3
850+
big_int_example:
851+
type: BigInt
852+
data: '1000000000000000000000000'
853+
```
854+
855+
- `Bool`: Specifies a Boolean value (`true` or `false`).
856+
- `String`: Specifies a String value.
857+
- `Int`: Specifies a 32-bit integer.
858+
- `Int8`: Specifies an 8-bit integer.
859+
- `BigDecimal`: Specifies a decimal number. Must be quoted.
860+
- `Bytes`: Specifies a hexadecimal string.
861+
- `List`: Specifies a list of items. Each item needs to specify its type and data.
862+
- `BigInt`: Specifies a large integer value. Must be quoted due to its large size.
863+
864+
This context is then accessible in your subgraph mapping files, enabling more dynamic and configurable subgraphs.
865+
811866
### Common AssemblyScript Issues
812867

813868
There are certain [AssemblyScript](https://github.com/AssemblyScript/assemblyscript) issues that are common to run into during subgraph development. They range in debug difficulty, however, being aware of them may help. The following is a non-exhaustive list of these issues:

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ dataSources:
109109
address: '0x2E645469f354BB4F5c8a05B3b30A929361cf77eC'
110110
abi: Gravity
111111
startBlock: 6175244
112+
context:
113+
foo:
114+
type: Bool
115+
data: true
116+
bar:
117+
type: String
118+
data: 'bar'
112119
mapping:
113120
kind: ethereum/events
114121
apiVersion: 0.0.6
@@ -146,6 +153,8 @@ The important entries to update for the manifest are:
146153

147154
- `dataSources.source.startBlock`: the optional number of the block that the data source starts indexing from. In most cases, we suggest using the block in which the contract was created.
148155

156+
- `dataSources.context`: key-value pairs that can be used within subgraph mappings. Supports various data types like `Bool`, `String`, `Int`, `Int8`, `BigDecimal`, `Bytes`, `List`, and `BigInt`. Each variable needs to specify its `type` and `data`. These context variables are then accessible in the mapping files, offering more configurable options for subgraph development.
157+
149158
- `dataSources.mapping.entities`: the entities that the data source writes to the store. The schema for each entity is defined in the schema.graphql file.
150159

151160
- `dataSources.mapping.abis`: one or more named ABI files for the source contract as well as any other smart contracts that you interact with from within the mappings.

0 commit comments

Comments
 (0)