502 IPFS Error Deploying Subgraphs to The Graph

Javery
Javery Owner
The Graph Infrastructure

For new folks we'll explain a bit about The Graph, for those that just want the solution go here.

How The Graph Works

The Graph is an amazing piece of technology that works to collect blockchain data in an easy-to-access way that can still be stored in a decentralised manner.

The premise is simple. You create a Subgraph where you define the data structure you want and the contracts/events that produce the data, and let it index from a particular block number and continue indexing with every block.

To deploy a new Subgraph, you generate the IPFS files locally the deployment to The Graph IPFS servers where anyone can pick them up for indexing.

Here in lies the issue.

The IPFS server within the Graph network is flakey at best.

IPFS Script Workaround

My new work around is to run a bash script that will keep looping through the deployment until it works. Simple, but effective.

Thanks to this post from ad0ll on Discord for the code.

#!/usr/bin/env bash

VERSION=$1

# Check if version is provided
if [ -z "$VERSION" ]; then
    echo "Usage: $0 <version>   # e.g. $0 v0.7.24"
    exit 1
fi

# Deploy the subgraph, retrying on IPFS gateway timeouts
while true; do
    # Pass the -l flag through to your yarn script.
    # Depending on your Yarn version, you may need the extra "--":
    # yarn run deploy-studio-sepolia -- -l "$VERSION"
    yarn deploy-studio-sepolia -l "$VERSION"
    if [ $? -eq 0 ]; then
        echo "✅ Deployed successfully (version $VERSION)"
        exit 0
    fi
    echo "⚠️  IPFS gateway timeout, retrying in 5s…"
    sleep 5
done

Make it executable by running chmod +x deploy-sepolia.sh

Now you can run this, and replace the version number.

./deploy-sepolia.sh v0.7.24

This keeps retrying until the issue goes away.

Hooray!