Redeploying a Suspended Subgraph
Tags: thegraph, subgraph, web3
Published: 2022-12-31 09:29:06

So, it's the end of the year and I was going through all my projects for the year when I came across some of the first subgraphs that I created and are no longer active, and I thought, why don't I try and see if i can reactivate them, and share the process with you while i'm at it?

First of all, I think it's important that i first of all point out that the reason we're redeploying the subgraph is because The graph protocol suspends subgraphs that have not been active over a long period of time. Active here means queries being made to the subgraph. So, it suspends any subgraphs that haven't being receiving queries to save resources.

How do we get our subgraphs back up, you might ask? Well, i'm curious too, so I'm going to do just that. You can follow along as well if you want to find out how.

* You need to install The Graph CLI globally using NPM or Yarn so that you can build and deploy your subgraphs. That is if you don't already have it installed. You can run the following command:
`npm install -g @graphprotocol/graph-cli` 

or `yarn global add @graphprotocol/graph-cli` If you are using Yarn instead.

* I'm assuming you still have the folder and files from when you initially deployed the subgraph. And if you do not, then you can pull it from the GitHub repository that you pushed your code. 

* cd into the directory that you have your subgraph code, and run the following command: 
```
graph auth --product hosted-service <access token>
```
You can get the subgraph access token from you subgraph's dashboard. 

* After you run the above command, you are going to get a response like this:
```
Deploy key set for https://api.thegraph.com/deploy/
```
* Then go on and run the following command for the actual deployment: 
```
graph deploy --product hosted-service <username>/<subgraph name>
```
In my case, my github username that I created the subgraph with is mufasasa and my subgraph name is 'raffle'. So, i'm going to run this command:
```
graph deploy --product hosted-service mufasasa/raffle
```

After I ran the command, Here'e what I got on my terminal:
```
apple@mohammeds-MacBook-Air raffle % graph deploy --product hosted-service mufasasa/raffle
  Skip migration: Bump mapping apiVersion from 0.0.1 to 0.0.2
  Skip migration: Bump mapping apiVersion from 0.0.2 to 0.0.3
  Skip migration: Bump mapping apiVersion from 0.0.3 to 0.0.4
  Skip migration: Bump mapping apiVersion from 0.0.4 to 0.0.5
  Skip migration: Bump mapping apiVersion from 0.0.5 to 0.0.6
  Skip migration: Bump manifest specVersion from 0.0.1 to 0.0.2
  Skip migration: Bump manifest specVersion from 0.0.2 to 0.0.4
✔ Apply migrations
✔ Load subgraph from subgraph.yaml
  Compile data source: Contract => build/Contract/Contract.wasm
✔ Compile subgraph
  Copy schema file build/schema.graphql
  Write subgraph file build/Contract/abis/Contract.json
  Write subgraph manifest build/subgraph.yaml
✔ Write compiled subgraph to build/
  Add file to IPFS build/schema.graphql
                .. QmbNuvtUUdbFB8rsqz1VtoSx53rXbG8wdgDQH6rN1pdsEs
  Add file to IPFS build/Contract/abis/Contract.json
                .. QmTBd3PKuZxHfyNSjKwsF6Srz3EdRTCz1M8fphmkuGyqBw
  Add file to IPFS build/Contract/Contract.wasm
                .. QmVAhCEFiXNG6LNVmTcz4HtfZ1WoJoTXDMmFM2uLUNz2P1
✔ Upload subgraph to IPFS

Build completed: QmT4KpqDiUmvNUyofvGJSojpnucEUHfBHiYFJWWYknhyCa

Deployed to https://thegraph.com/explorer/subgraph/mufasasa/raffle

Subgraph endpoints:
Queries (HTTP):     https://api.thegraph.com/subgraphs/name/mufasasa/raffle
```

And with that, my subgraph is back online and we can continue making queries to it!!

Thanks for coming along this far with me, enjoy the holidays, and cheers to a wonderful and fulfilling 2023