What is The Graph?
The Graph is a protocol for indexing and querying data from blockchains, starting with Ethereum. Developers build applications with open APIs called subgraphs to easily access on-chain data that is indexed by a network of node operators. Subgraphs are open source so anyone can use the APIs to build decentralized applications. Many Ethereum applications have already built subgraphs and use them today including: Audius, Uniswap, Opyn, ENS, DAOstack, Synthetix, Moloch and more.
Over 20,000 developers have contributed to developing subgraphs across more than 20 chains. The Graph decentralizes the query and API layer of Web 3, removing a tradeoff dApp developers struggle with today: whether to build an application that is performant or to build an app that is truly decentralized.
How The Graph work?
The Graph learns what and how to index Ethereum data based on subgraph descriptions, known as the subgraph manifest. The subgraph description defines the smart contracts of interest for a subgraph, the events in those contracts to pay attention to, and how to map event data to data that The Graph will store in its database.
Once you have written a
subgraph manifest, you use the Graph CLI to store the definition in IPFS and tell the indexer to start indexing data for that subgraph.
This diagram gives more detail about the flow of data once a subgraph manifest has been deployed, dealing with Ethereum transactions:
The flow follows these steps:
- A decentralized application adds data to Ethereum through a transaction on a smart contract.
- The smart contract emits one or more events while processing the transaction.
- Graph Node continually scans Ethereum for new blocks and the data for your subgraph they may contain.
- Graph Node finds Ethereum events for your subgraph in these blocks and runs the mapping handlers you provided. The mapping is a WASM module that creates or updates the data entities that Graph Node stores in response to Ethereum events.
- The decentralized application queries the Graph Node for data indexed from the blockchain, using the node's GraphQL endpoint. The Graph Node in turn translates the GraphQL queries into queries for its underlying data store in order to fetch this data, making use of the store's indexing capabilities. The decentralized application displays this data in a rich UI for end-users, which they use to issue new transactions on Ethereum. The cycle repeats.
Read full Article: CLICK HERE