THE GRAPH CHEAT SHEET
A developer’s cheat sheet for getting up to speed with subgraphs in 15 minutes
The Graph is the indexing and query layer of web3. Developers build and publish open APIs, called subgraphs, that applications can easily query using GraphQL.
A subgraph is a decentralized GraphQL API layer that sits between your UI layer and blockchain data layer. Subgraphs let you index data from the blockchain and query it over to your app’s frontend.
Learn more at thegraph.com/ecosystem/learn/
subgraph.yaml
: A YAML file that describes the subgraph configuration such as smart contract address, entities, events, etc.schema.graphql
: A GraphQL schema that defines the data you want your GraphQL API to query to serve to your frontend clientAssemblyScript Mappings
: AssemblyScript code that translates from the event data emitted from the smart contract to the entities defined in your schema (e.g. mapping.ts
in this cheatsheet)<aside> 💡 Note: The subgraph folder structure includes several other files and folders such as generated, node_modules, build, etc. The above list only delineates the files that are involved in the subgraph definition process.
</aside>
Using npm
yarn global add @graphprotocol/graph-cli
Using yarn
npm install -g @graphprotocol/graph-cli
graph init --index-events
<aside>
💡 Currently, the product option subgraph-studio
is only available for subgraphs on Ethereum Mainnet
</aside>