Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

paginate_all

Paginate through every result of a GraphQL connection using cursor-based pagination.

Signature

pub async fn paginate_all<V, N, BuildVariables, ExtractPage>(
    &self,
    first: Option<i64>,
    last: Option<i64>,
    build_variables: BuildVariables,
    extract_page: ExtractPage,
) -> Result<Vec<N>, anyhow::Error>
where
    V: Variables + Serialize + Debug,
    <V::Query as GraphQLQuery>::ResponseData: Debug,
    BuildVariables: Fn(Option<String>, Option<String>, Option<i64>, Option<i64>) -> V,
    ExtractPage:    Fn(<V::Query as GraphQLQuery>::ResponseData) -> (Vec<N>, PageInfo);

Example

use {
    anyhow::Result,
    dango_sdk::{HttpClient, PageInfo, accounts},
};
 
#[tokio::main]
async fn main() -> Result<()> {
    let client = HttpClient::new("https://api-mainnet.dango.zone")?;
 
    let all_accounts = client
        .paginate_all(
            Some(100),
            None,
            |after, before, first, last| accounts::Variables {
                after,
                before,
                first,
                last,
                ..Default::default()
            },
            |data| {
                let pi = data.accounts.page_info;
                (data.accounts.nodes, PageInfo {
                    start_cursor:     pi.start_cursor,
                    end_cursor:       pi.end_cursor,
                    has_next_page:    pi.has_next_page,
                    has_previous_page: pi.has_previous_page,
                })
            },
        )
        .await?;
 
    println!("fetched {} accounts", all_accounts.len());
    Ok(())
}

Parameters

firstOption<i64>. Page size for forward pagination. Pass Some(n) and last = None.

lastOption<i64>. Page size for backward pagination. Pass Some(n) and first = None.

build_variablesFn(after, before, first, last) -> V. Builds the query variables for a single page given the cursors.

extract_pageFn(ResponseData) -> (Vec<N>, PageInfo). Pulls the node list and pagination metadata out of the typed response.

Returns

Vec<N> — every node in the connection, concatenated across pages. Forward pagination preserves source order; backward pagination reverses each page so the final Vec is oldest-first.

Notes

  • Exactly one of first or last must be Some. Other combinations error with "paginate_all requires exactly one of firstorlast to be Some".
  • Each page is a fresh GraphQL call. Mind the HTTP rate limit on connections with thousands of nodes.
  • For the indexer's standard connections (accounts, transfers, transactions, blocks, events, messages), the typed wrappers — paginate_accounts, etc. — are simpler.

See also