Creating Subgraphs
A subgraph extracts data from a blockchain, processing it and storing it so that it can be easily queried via GraphQL.
The subgraph definition consists of a few files:
subgraph.yaml: a YAML file containing the subgraph manifestschema.graphql: a GraphQL schema that defines what data is stored for your subgraph, and how to query it via GraphQLAssemblyScript Mappings: AssemblyScript code that translates from the event data to the entities defined in your schema (e.g.mapping.tsin this tutorial)
In order to use your subgraph on The Graph's decentralized network, you will need to create an API key. It is recommended that you add signal to your subgraph with at least 10,000 GRT.
Before you go into detail about the contents of the manifest file, you need to install the Graph CLI which you will need to build and deploy a subgraph.
Install the Graph CLI
The Graph CLI is written in JavaScript, and you will need to install either yarn or npm to use it; it is assumed that you have yarn in what follows.
Once you have yarn, install the Graph CLI by running
Install with yarn:
yarn global add @graphprotocol/graph-cli
Install with npm:
npm install -g @graphprotocol/graph-cli
Once installed, the graph init command can be used to set up a new subgraph project, either from an existing contract or from an example subgraph. This command can be used to create a subgraph on the Subgraph Studio by passing in graph init --product subgraph-studio. If you already have a smart contract deployed to your preferred network, bootstrapping a new subgraph from that contract can be a good way to get started.