Custom Subgraph queries

circle-info

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.

Subgraph schemas

To be able to fetch data from the Subgraph, we first have to understand their GraphQL schemasarrow-up-right. You can find the schemas associated with each Subgraph included officially with Aragon Connect in the Connectors Reference section.

Creating a custom query

You can use any tool that supports GraphQL, but for simplicity in illustration, we have chosen graphql-tagarrow-up-right in the following examples:

import gql from 'graphql-tag'
import { GraphQLWrapper } from '@aragon/connect-thegraph'

// Construct the query
const QUERY = gql`
query {
  votes(where:{
    appAddress: "${VOTING_APP_ADDRESS}"
  }) {
    id
    metadata
    creator
  }
}
`

// Create the GraphQL wrapper using the specific Subgraph URL
const wrapper = new GraphQLWrapper(VOTING_SUBGRAPH_URL)

// Invoke the custom query and receive data
const results = await wrapper.performQuery(QUERY)

const { votes } = results.data
circle-exclamation

Subscriptions

It is also possible to create a subscription to a custom query:

Last updated

Was this helpful?