Skip to content

Commit 34fb37c

Browse files
Docs for graph add (#173)
* Docs for graph add * Add new line * Remove extra whitespace
1 parent a70a1f6 commit 34fb37c

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,37 @@ The `<SUBGRAPH_SLUG>` is the ID of your subgraph in Subgraph Studio, it can be f
2525

2626
The second mode `graph init` supports is creating a new project from an example subgraph. The following command does this:
2727

28-
```
28+
```sh
2929
graph init --studio <SUBGRAPH_SLUG>
3030
```
3131

3232
The example subgraph is based on the Gravity contract by Dani Grant that manages user avatars and emits `NewGravatar` or `UpdateGravatar` events whenever avatars are created or updated. The subgraph handles these events by writing `Gravatar` entities to the Graph Node store and ensuring these are updated according to the events. The following sections will go over the files that make up the subgraph manifest for this example.
3333

34+
## Add New dataSources To An Existing Subgraph
35+
36+
Since `v0.31.0` the `graph-cli` supports adding new dataSources to an existing subgraph through the `graph add` command.
37+
38+
```sh
39+
graph add <address> [<subgraph-manifest default: "./subgraph.yaml">]
40+
41+
Options:
42+
43+
--abi <path> Path to the contract ABI (default: download from Etherscan)
44+
--contract-name Name of the contract (default: Contract)
45+
--merge-entities Whether to merge entities with the same name (default: false)
46+
--network-file <path> Networks config file path (default: "./networks.json")
47+
```
48+
49+
The `add` command will fetch the ABI from Etherscan (unless an ABI path is specified with the `--abi` option), and will create a new `dataSource` in the same way that `graph init` command creates a `dataSource` `--from-contract`, updating the schema and mappings accordingly.
50+
51+
The `--merge-entities` option identifies how the developer would like to handle `entity` and `event` name conflicts:
52+
- If `true`: the new `dataSource` should use existing `eventHandlers` & `entities`.
53+
- If `false`: a new entity & event handler should be created with `${dataSourceName}{EventName}`.
54+
55+
The contract `address` will be written to the `networks.json` for the relevant network.
56+
57+
> **Note:** When using the interactive cli, after successfully running `graph init`, you'll be prompted to add a new `dataSource`.
58+
3459
## The Subgraph Manifest
3560

3661
The subgraph manifest `subgraph.yaml` defines the smart contracts your subgraph indexes, which events from these contracts to pay attention to, and how to map event data to entities that Graph Node stores and allows to query. The full specification for subgraph manifests can be found [here](https://github.com/graphprotocol/graph-node/blob/master/docs/subgraph-manifest.md).

0 commit comments

Comments
 (0)