General
General overview over Subgraphs
A Subgraph is a piece of code which gets deployed to a TheGraph Node. It indexes data from the blockchain through handlers which listen on emitted events of smart contracts.
Aavegotchi provides multiple subgraphs to fetch fast information from the chain, e.g. stats about the aavegotchi, the marketplace or even the svgs from the aavegotchis itself.
How to Query a Subgraph
The following describes how to interact with Graph endpoints in general. If you know how to work with GraphQL endpoints you can skip this section.
How to Query the Graphs in your app
In order to query with your app the graph you need a graphQL client. There are tons of libraries out there: https://graphql.org/code/. In the following example we work with apollo-fetch. A tiny GraphQL NodeJS Library which has a wide acceptance https://www.npmjs.com/package/apollo-fetch.
You create a client for the subgraph:
and afterwards create and send a query and log the response:
The output should be:
In case you do an error the subgraph responses with an error. For example:
returns
Query historical data
If a graph gets deployed it starts indexing the data from a specific block. It iterates through all the events and maintains its own state in a postgresql. The state contains not only the latest information, but also all the previous information. This allows you to fetch data from the history. The following for example will return the name of the aavegotchi at block 18250000:
Query for specific items or a set of items
You can either fetch single items or multiple. The difference is a s at the end of the entity. This query will return one aavegotchi:
whereas this query will return a list of aavegotchis
Last updated