Queries
Nested Object Queries
Learn how to traverse relationships between objects using hierarchical queries.
Nested Object Queries
This represents an example of hierarchical querying where multiple objects can be accessed in a structured manner.
The maximum depth is 2.
Example Query
Fetch the Allnodes provider with its associated reward options and validators:
{
providers(where: { names: ["Allnodes"] }, limit: 1) {
id
name
slug
rewardOptions(where: { typeKeys: ["pos"] }, limit: 10) {
id
inputAssets(limit: 10) {
name
}
validators(limit: 10) {
id
address
}
}
}
}How It Works
- The query starts at the
providerslevel, filtering for "Allnodes" - Within each provider, it retrieves
rewardOptionsfiltered by type - For each reward option, it fetches
inputAssetsandvalidators
This nested structure allows you to get related data in a single request instead of making multiple API calls.
Always specify limit at each level of nesting to control the amount of data returned and optimize performance.