Custom Subgraph queries
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 schemas. 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-tag in the following examples:
1
import gql from 'graphql-tag'
2
import { GraphQLWrapper } from '@aragon/connect-thegraph'
3
4
// Construct the query
5
const QUERY = gql`
6
query {
7
votes(where:{
8
appAddress: "${VOTING_APP_ADDRESS}"
9
}) {
10
id
11
metadata
12
creator
13
}
14
}
15
`
16
17
// Create the GraphQL wrapper using the specific Subgraph URL
18
const wrapper = new GraphQLWrapper(VOTING_SUBGRAPH_URL)
19
20
// Invoke the custom query and receive data
21
const results = await wrapper.performQuery(QUERY)
22
23
const { votes } = results.data
Copied!
gql is exposed from graphql-tag and is a utility that parses strings into structured GraphQL query objects.

Subscriptions

It is also possible to create a subscription to a custom query:
1
import gql from 'graphql-tag'
2
import { GraphQLWrapper } from '@aragon/connect-thegraph'
3
4
// Construct the query
5
const QUERY = gql`
6
query miniMeToken($id: String!, $address: String!) {
7
miniMeToken(id: $id) {
8
id
9
totalSupply
10
holders(where: { address: $address }) {
11
address
12
balance
13
}
14
}
15
}
16
`
17
18
// Create the GraphQL wrapper using the specific Subgraph URL
19
const wrapper = new GraphQLWrapper(TOKEN_MANAGER_SUBGRAPH)
20
21
// Create the subscription and receive updates every time the data changes
22
const subscription = wrapper.subscribeToQuery(
23
QUERY,
24
{
25
id: TOKEN_ID,
26
address: ACCOUNT_ADDRES,
27
},
28
(error, results) => {
29
if (error) throw error
30
31
// Handle each new result
32
const { miniMeToken } = results.data
33
}
34
)
35
36
// Stop receiving updates
37
subscription.unsubscribe()
Copied!
Last modified 1mo ago