Sort Query Results
This is an example of a query sorting the list of assets alphabetically.
{
assets(order: {isLaunched: desc, name: asc}, limit: 10) {
name
symbol
slug
isLaunched
}
}
The "order" argument sorts the results in a specific order, based on the values provided.
The sort order can be ascending (asc)
or descending (desc)
. The field by which the results are sorted is specified as an object with the field name and its order, as in {field_name: order}
. The order of the values in the argument determines the order of the sorting. In the example above, the results first show a list of assets that are launched, sorted by name, followed by a list of assets that are not launched, sorted by name.
The order argument is commonly used in conjunction with pagination arguments such as limit to sort and retrieve a specific set of results.
Ordering can be done also by changePercentagesKey
or changeAbsolutesKey
in combination with metricKey_asc
or metricKey_desc
. In this case, the order direction is taken from metricKey.
This is an example of a query sorting the list of the top 10 assets by staking marketcap given the change percentage of the past 30 days.
{
assets(order: {metricKey_desc: "staking_marketcap", changePercentagesKey: _30d} limit: 10) {
id
name
slug
description
symbol
metrics (where: {metricKeys: ["staking_marketcap"]} limit: 10) {
metricKey
defaultValue
changePercentages
}
}
}