Aavegotchi Docs
Official WebsiteDapp
  • Welcome to Aavegotchi
    • Introduction
  • Own. Trade. Earn.
    • What is True Ownership?
    • Tokens
      • GHST Token
      • Gotchus Alchemica
      • GLTR Token
    • Game Items
      • Aavegotchis
      • Portals
      • Wearables
      • The Forge
      • Gotchiverse
    • Trading
      • Aavegotchi Baazaar
      • Auction House
    • Earning in Aavegotchi
      • Rarity Farming
      • Staking
      • Playing Games
  • Gaming
    • Aavegotchi Gaming Console
    • Live Games
    • Assets
      • Badges
      • Experience Points
      • Skins
      • [REDACTED]
  • Geist
    • Overview
    • FAQ
  • Governance
    • About AavegotchiDAO
    • Creating a Proposal
    • Voting on Proposals
  • developers
    • Aavegotchi Contracts
      • Reading from Aavegotchi Contracts
        • Fetching Onchain SVGs
      • Writing to Aavegotchi Contracts
      • Extending Aavegotchi Contracts
        • Upgrading
        • Security
        • Deployment
        • Governance
      • About EIP-2535 Diamonds
        • Facets
      • maTokens
      • Concepts
      • Deployed Contracts
        • Aavegotchi Diamond
        • Forge Diamond
        • Wearable Diamond
        • Gotchiverse Realm Diamond
        • Installation Diamond
        • Tile Diamond
    • Subgraphs
      • General
      • Core Matic Subgraph
      • SVG Subgraphs
      • Gotchiverse Subgraph
      • FAKE Gotchi Subgraph
Powered by GitBook
On this page
  • How to Query a Subgraph
  • How to Query the Graphs in your app
  • Query historical data
  • Query for specific items or a set of items

Was this helpful?

  1. developers
  2. Subgraphs

General

General overview over Subgraphs

PreviousSubgraphsNextCore Matic Subgraph

Last updated 1 year ago

Was this helpful?

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: . In the following example we work with apollo-fetch. A tiny GraphQL NodeJS Library which has a wide acceptance .

You create a client for the subgraph:

const { createApolloFetch } = require('apollo-fetch');

const uri = 'https://api.thegraph.com/subgraphs/name/aavegotchi/aavegotchi-core-matic';
const apolloFetch = createApolloFetch({ uri });

and afterwards create and send a query and log the response:

let query = `{ 
    aavegotchi(id: "4430"){
        name
    }
}`;

apolloFetch({ query }).then(result => {
    const { data, errors, extensions } = result;
    if(errors !== undefined) {
        console.error(JSON.stringify(errors))
    }
    console.log(data);
}).catch(error => {
    console.error(error);
});

The output should be:

{ aavegotchi: { name: 'ChillETH' } }

In case you do an error the subgraph responses with an error. For example:

{ 
    aavegotchi(id: "4430"){
        fieldWhichDoesNOtExist
    }
}

returns

[{"locations":[{"line":4,"column":9}],"message":"Type `Aavegotchi` has no field `fieldWhichDoesNOtExist`"}]

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:

{ 
    aavegotchi(id: "4430" block: { number: 18250000 }){
        name
    }
}

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:

{ 
    aavegotchi(id: "4430"){
        name
    }
}

whereas this query will return a list of aavegotchis

{ 
    aavegotchis(orderBy: name){
        name
    }
}
https://graphql.org/code/
https://www.npmjs.com/package/apollo-fetch