The Graph
What is the graph? The Graph is an indexing protocol for querying blockchain and IPFS data that exposes a richer query layer for apps to consume.
It's difficult and time-intensive to read data directly from the chain.
Benefit
Engineering teams could architect a centralized indexing database and serve API requests from these servers but this:
- requires expert engineering knowledge
- requires setup hardware resources
- breaks the security properties of decentralization
Config
- Create an account
- Create a subgraph
- Install the Cli
yarn global add @graphprotocol/graph-cli
Init the project from a deployed contract.
graph init --from-contract CONTRACT-ADDRESS --network mumbai --contract-name Blog --index-events
Dev Flow
- Define Entities
- graph codegen
- update subgraph.yaml
- get start block from polygonscan.com
- enter startBlock into subgraph.yaml
- update src/mappings
- graph build
- graph auth
- yarn deploy
- query subgraph
- optimise app queries
Links
Context
- Onchain Interaction — The frontend layer that consumes indexed data
- GraphQL — Query patterns The Graph exposes
- Data Fetching — How indexed data flows into React
Questions
When does a custom indexer outperform The Graph for your specific query patterns?
- What is the real latency between on-chain event and indexed availability?
- How do you handle subgraph reorgs and chain reorganizations in the UI?