Docs
Search⌘ K
  • Home
  • About The Graph
  • Supported Networks
  • Protocol Contracts
  • Subgraphs
    • Substreams
      • Indexer Software
        • Gateway Software
          • Data Services
            • AI Tooling
            • Resources
              Subgraphs

              4 minutes

              Subgraphs Overview

              What is a Subgraph?

              A Subgraph is a custom, open API that extracts data from a blockchain, processes it, and stores it so it can be easily queried via GraphQL. Subgraphs can be run locally via Graph Node or be published onto The Graph Network for other consumers to query it openly via multiple Gateway Providers.

              Subgraph Capabilities

              • Access Data: Subgraphs enable the querying and indexing of blockchain data for web3.
              • Build: Developers can build, deploy, and publish Subgraphs to The Graph Network. To get started, check out the Subgraph developer Quick Start.
              • Index & Query: Once a Subgraph is indexed, anyone can query it. Explore and query all Subgraphs published to the network in Graph Explorer.

              Anatomy of a Subgraph

              A Subgraph’s manifest defines the smart contracts & network that will be indexed, the 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 Subgraph definition consists of the following files:

              • subgraph.yaml: Contains the Subgraph manifest

              • schema.graphql: A GraphQL schema defining the data stored and how to query it

              • mapping.ts: AssemblyScript Mappings⁠ that translate event data into entities in your schema

              To learn more about each Subgraph component, check out Creating a Subgraph.

              Subgraph Development Lifecycle

              Subgraph Lifecycle

              Every Subgraph follows the same path: build it, publish it to The Graph Network, and query it through a gateway. Here’s a step-by-step breakdown:

              1. Create a Subgraph
              2. Test and stage the Subgraph
              3. Publish and curate the Subgraph on The Graph Network
              4. Query the Subgraph

              Build Locally

              Great Subgraphs start with a local development environment and unit tests. Developers use Graph CLI⁠, a command-line interface tool for building and deploying Subgraphs on The Graph. They can also use Graph TypeScript and Matchstick to create robust Subgraphs. Subgraph Skills also give AI assistants expert knowledge for developing, testing, and deploying Subgraphs.

              Test and Stage

              Before you publish, check that your Subgraph indexes without errors and returns the data you expect. You can run it locally with Graph Node Dev Mode, or deploy it to Subgraph Studio, operated by The Graph Foundation, which indexes the deployed version and gives you a development query URL. See Testing and Staging.

              Publish to and Curate on The Graph Network

              When you’re happy with your Subgraph, you can publish it to The Graph Network.

              • This is an on-chain action, which registers the Subgraph and makes it discoverable for Gateway Providers, Indexers, and other data consumers.
              • Published Subgraphs have a corresponding NFT, which defines the ownership of the Subgraph. You can transfer the Subgraph’s ownership by sending the NFT.
              • Published Subgraphs have associated metadata, which provides other network participants with useful context and information.

              You can publish with the Graph CLI or in Subgraph Studio.

              Then add curation signal: GRT deposited on a Subgraph to tell Indexers it’s worth indexing. Published Subgraphs are unlikely to be picked up by Indexers without it. You can add signal in the same transaction when you publish. Learn how much signal to add.

              Querying Subgraphs

              Applications query a published Subgraph through a gateway, which routes each query to Indexers and bills you for it. These docs use The Graph Foundation’s Gateway (gateway.thegraph.com) with API keys and billing in Subgraph Studio. While Studio can be used to manage your Subgraphs, there are multiple Subgraph Gateway Providers that serve Subgraph data. You can query through any of them without republishing. Learn more about querying Subgraphs.

              Updating, Deleting and Transferring Subgraphs

              To update your Subgraph with bug fixes or new functionalities, publish a new version, which points the Subgraph to a new deployment on-chain. You can test new versions locally or in Subgraph Studio before you publish them, regardless of your Gateway Provider.

              • If you selected “auto-migrate” when you applied the signal, updating the Subgraph will migrate any signal to the new version and incur the curation tax on the migrated signal.
              • This signal migration should prompt Indexers to start indexing the new version of the Subgraph, so it should soon become available for querying.

              If you no longer need a published Subgraph, you can delete or transfer it. When a Subgraph is deleted, Curators can withdraw their signaled GRT.

              ⁠Edit on GitHub⁠

              Protocol ContractsQuick Start
              On this page
              • What is a Subgraph?
              • Subgraph Capabilities
              • Anatomy of a Subgraph
              • Subgraph Development Lifecycle
              • Build Locally
              • Test and Stage
              • Publish to and Curate on The Graph Network
              • Querying Subgraphs
              • Updating, Deleting and Transferring Subgraphs
              The GraphStatusTestnetBrand AssetsForumSecurityPrivacy PolicyTerms of Service