# Subgraphs management

**URL:** <https://forum.thegraph.com/t/subgraphs-management/3415>\
**Category:** General\
**Tags:** indexer, subgraph-devs\
**Created:** [June 17, 2022, 12:17pm UTC](https://forum.thegraph.com/t/subgraphs-management/3415 "2022-06-17T12:17:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stmx38](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.thegraph.com/stmx38/32/1658_2.png) [@stmx38](https://forum.thegraph.com/u/stmx38)\
**Post date:** [June 17, 2022, 12:17pm UTC](https://forum.thegraph.com/t/subgraphs-management/3415/1 "2022-06-17T12:17:07Z")

</div>

## Subgraph management

The Graph is spreading across the Internet and it is used with a lot of different projects.

At some point it may be required to manage deployed subgraphs. It is generally related to the cases:

1. Deploy subgraph
2. Deploy new version of subgraph - the old one will remain in the list and database
3. Reassign subgraph to a different index node
4. Pause indexing subgraph - subgraph will remain in the list and database

For this, we can use the following approaches

1. [Graph CLI](#graph-cli-2)
2. [Graph node API](#graph-node-api-3)
3. [Graphman](#graphman-10)

### Graph CLI

[The Graph CLI (graph-cli)](https://github.com/graphprotocol/graph-cli) is a tool for subgraph build and deployment

```bash
# Install graph-cli
yarn global add @graphprotocol/graph-cli

# Install dependencies
yarn install

# Codegen
yarn codegen

# Build
yarn build

# Graph create
graph create ${SUBGRAPH_NAME} \
  --node ${INDEX_NODE_ENDPOINT} \

# Graph deploy
graph deploy ${SUBGRAPH_NAME} \
  --version-label ${GITHUB_REF_NAME} \
  --node ${INDEX_NODE_ENDPOINT} \
  --ipfs ${IPFS_ENDPOINT}

```

### Graph node API

We can find in [graph-node/server/json-rpc/src/lib.rs](https://github.com/graphprotocol/graph-node/blob/master/server/json-rpc/src/lib.rs) defined 4 methods

```auto
subgraph_create
subgraph_deploy
subgraph_remove
subgraph_reassign

```

And we can interact with the Graph node JSON-RPC using the port set by [`--admin-port`](https://github.com/graphprotocol/graph-node#running-a-local-graph-node) option which is by default 8020 and use different HTTP clients like [httpie](https://httpie.io/) and [curl](https://curl.se/)

```bash
# Debian
apt install httpie curl

# RHEL
yum install httpie curl

# Python
pip install httpie

```

#### Create subgraph deployment

```bash
# httpie
http post index-node:8020 \
  jsonrpc=2.0 \
  id=2 \
  method=subgraph_create \
  params:='{"name": "indexer-agent/ke3y2c7Kai"}'

# curl
curl -X POST index-node:8020 \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc": "2.0", "id": "2", "method": "subgraph_create", "params": {"name": "indexer-agent/ke3y2c7Kai"}}'

```

#### Deploy subgraph

```bash
# httpie
http post index-node:8020 \
  jsonrpc=2.0 \
  id=2 \
  method=subgraph_deploy \
  params:='{"name": "indexer-agent/ke3y2c7Kai", "ipfs_hash": "QmWK7Phe4L6H3dzXHh48G1TrYDugeAVaFroUke3y2c7Kai"}'

# curl
curl -X POST index-node:8020 \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc": "2.0", "id": "2", "method": "subgraph_deploy", "params": {"name": "indexer-agent/ke3y2c7Kai", "ipfs_hash": "QmWK7Phe4L6H3dzXHh48G1TrYDugeAVaFroUke3y2c7Kai"}}'

```

#### Reassign subgraph

```bash
# httpie
http post index-node:8020 \
  jsonrpc=2.0 \
  id=2 \
  method=subgraph_reassign \
  params:='{"ipfs_hash": "QmWK7Phe4L6H3dzXHh48G1TrYDugeAVaFroUke3y2c7Kai", "node_id": "index_node_2"}'

# curl
curl -X POST index-node:8020 \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc": "2.0", "id": "2", "method": "subgraph_reassign", "params": {"ipfs_hash": "QmWK7Phe4L6H3dzXHh48G1TrYDugeAVaFroUke3y2c7Kai", "node_id": "index_node_2"}}'

```

#### Pause subgraph

Assign to non-existing node id

```bash
# httpie
http post index-node:8020 \
  jsonrpc=2.0 \
  id=2 \
  method=subgraph_reassign \
  params:='{"ipfs_hash": "QmWK7Phe4L6H3dzXHh48G1TrYDugeAVaFroUke3y2c7Kai", "node_id": "paused"}'

# curl
curl -X POST index-node:8020 \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc": "2.0", "id": "2", "method": "subgraph_reassign", "params": {"ipfs_hash": "QmWK7Phe4L6H3dzXHh48G1TrYDugeAVaFroUke3y2c7Kai", "node_id": "paused"}}'

```

#### Resume subgraph

Assign to an existing node id

```bash
# httpie
http post index-node:8020 \
  jsonrpc=2.0 \
  id=2 \
  method=subgraph_reassign \
  params:='{"ipfs_hash": "QmWK7Phe4L6H3dzXHh48G1TrYDugeAVaFroUke3y2c7Kai", "node_id": "index_node_2"}'

# curl
curl -X POST index-node:8020 \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc": "2.0", "id": "2", "method": "subgraph_reassign", "params": {"ipfs_hash": "QmWK7Phe4L6H3dzXHh48G1TrYDugeAVaFroUke3y2c7Kai", "node_id": "index_node_2"}}'

```

#### Remove subgraph

```bash
# httpie
http post index-node:8020 \
  jsonrpc=2.0 \
  id=2 \
  method=subgraph_remove \
  params:='{"name": "indexer-agent/ke3y2c7Kai", "ipfs_hash": "QmWK7Phe4L6H3dzXHh48G1TrYDugeAVaFroUke3y2c7Kai"}'

# curl
curl -X POST index-node:8020 \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc": "2.0", "id": "2", "method": "subgraph_remove", "params": {"name": "indexer-agent/ke3y2c7Kai", "ipfs_hash": "QmWK7Phe4L6H3dzXHh48G1TrYDugeAVaFroUke3y2c7Kai"}}'

```

> Will remove the mapping from the given name to the underlying deployment. If no other subgraph name uses that deployment, it becomes eligible for removal, and the steps for removing unused deployments will delete its data.

### Graphman

The `graphman` command is included in the official containers, and we can `docker exec` into our graph-node container to run it. It requires a [configuration file](https://github.com/graphprotocol/graph-node/blob/master/docs/config.md). For more information please see [Common maintenance tasks](https://github.com/graphprotocol/graph-node/blob/master/docs/maintenance.md).

1. Login to the graph node container

2. Create config file

3. Get information about subgraph

4. Unregister a subgraph name with a Graph node

5. Compiles a list of unused deployments

6. Inspect the list

7. Remove the deployments that have previously marked for removal

8. Reassign subgraph

9. Pause subgraph

10. Resume subgraph

---

<div class="post-metadata">

**Author:** ![indexer\_payne](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.thegraph.com/indexer_payne/32/44_2.png) [@indexer\_payne](https://forum.thegraph.com/u/indexer_payne)\
**Post date:** [June 17, 2022, 12:20pm UTC](https://forum.thegraph.com/t/subgraphs-management/3415/2 "2022-06-17T12:20:59Z")

</div>

Very nice post!  
I forwarded this to #indexers-software channel in Discord and pinned it!

---

<div class="post-metadata">

**Author:** ![stmx38](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.thegraph.com/stmx38/32/1658_2.png) [@stmx38](https://forum.thegraph.com/u/stmx38)\
**Post date:** [June 17, 2022, 12:25pm UTC](https://forum.thegraph.com/t/subgraphs-management/3415/3 "2022-06-17T12:25:21Z")

</div>

Thank you! As an inspiration I used your and other members notes from the mentioned channel - just to have all in one place and easy accessible in the web.

---

<div class="post-metadata">

**Author:** ![napolean](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.thegraph.com/napolean/32/2142_2.png) [@napolean](https://forum.thegraph.com/u/napolean)\
**Post date:** [June 21, 2022, 5:41pm UTC](https://forum.thegraph.com/t/subgraphs-management/3415/4 "2022-06-21T17:41:00Z")

</div>

Very helpful commands for all the Graph indexers out there.  
The commands will be great help for new indexers joining the network.
