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: pages/en/developing/creating-a-subgraph.mdx
+26-1Lines changed: 26 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -25,12 +25,37 @@ The `<SUBGRAPH_SLUG>` is the ID of your subgraph in Subgraph Studio, it can be f
25
25
26
26
The second mode `graph init` supports is creating a new project from an example subgraph. The following command does this:
27
27
28
-
```
28
+
```sh
29
29
graph init --studio <SUBGRAPH_SLUG>
30
30
```
31
31
32
32
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.
33
33
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.
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
+
34
59
## The Subgraph Manifest
35
60
36
61
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