The data that the Subgraphs contain can be used to answer complex questions. While the available connectors create a simplified abstraction by implementing queries that cover the most generic use cases, you can go further by invoking your own queries.
To be able to fetch data from the Subgraph, we first have to understand their GraphQL schemas. You can find the schemas associated with each Subgraph included officially with Aragon Connect in the Connectors Reference section.
You can use any tool that supports GraphQL, but for simplicity in illustration, we have chosen graphql-tag
in the following examples:
import gql from 'graphql-tag'import { GraphQLWrapper } from '@aragon/connect-thegraph'​// Construct the queryconst QUERY = gql`query {votes(where:{appAddress: "${VOTING_APP_ADDRESS}"}) {idmetadatacreator}}`​// Create the GraphQL wrapper using the specific Subgraph URLconst wrapper = new GraphQLWrapper(VOTING_SUBGRAPH_URL)​// Invoke the custom query and receive dataconst results = await wrapper.performQuery(QUERY)​const { votes } = results.data
gql
is exposed from graphql-tag
and is a utility that parses strings into structured GraphQL query objects.
It is also possible to create a subscription to a custom query:
import gql from 'graphql-tag'import { GraphQLWrapper } from '@aragon/connect-thegraph'​// Construct the queryconst QUERY = gql`query miniMeToken($id: String!, $address: String!) {miniMeToken(id: $id) {idtotalSupplyholders(where: { address: $address }) {addressbalance}}}`​// Create the GraphQL wrapper using the specific Subgraph URLconst wrapper = new GraphQLWrapper(TOKEN_MANAGER_SUBGRAPH)​// Create the subscription and receive updates every time the data changesconst subscription = wrapper.subscribeToQuery(QUERY,{id: TOKEN_ID,address: ACCOUNT_ADDRES,},(error, results) => {if (error) throw error​// Handle each new resultconst { miniMeToken } = results.data})​// Stop receiving updatessubscription.unsubscribe()