πŸ“Cursor Pagination

Learn how to use cursor pagination to get all the data from Airstack queries.

Airstack uses cursor-based paginations to retrieve huge amounts of on-chain and off-chain data that is broken down into pages with a maximum of 200 objects returned in a single response.

If you're look on how to implement pagination using the Airstack SDKs in your application, click here.

How Does It Work?

Each response result from an API call is a page and is indicated by a cursor value.

Thus, in order to go to the next (or previous) page, you will need to get the cursor value for the next (or previous) page, which is provided in every Airstack GraphQL schema as pageInfo.nextCursor (or pageInfo.prevCursor):

Try Demo

Code

query MyQuery {
  TokenBalances(
    input: {filter: {tokenAddress: {_eq: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D"}}, blockchain: ethereum, limit: 200}
  ) {
    TokenBalance {
      owner {
        identity
      }
    }
    pageInfo {
      hasNextPage # Booelan indicating if the next page of data exist
      hasPrevPage # Booelan indicating if the previous page of data exist
      nextCursor # cursor to next page (2nd page)
      prevCursor # cursor to prev page
    }
  }
}

If pageInfo.nextCursor or pageInfo.prevCursor is returned as an empty string, then it implies that there is no more next or previous page, respectively.

Once you have the cursor for the next page, you can use the cursor value to retrieve data from the 2nd page by making another API call with the pageInfo.nextCursor value provided in the cursor input filter:

Try Demo

Code

query MyQuery {
  TokenBalances(
    input: {
      filter: {
        tokenAddress: {
          _eq: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D"
        }
      },
      blockchain: ethereum,
      limit: 200,
      # Cursor of the 2nd page
      cursor: "eyJMYXN0VmFsdWVzTWFwIjp7Il9pZCI6eyJWYWx1ZSI6IjEweGJjNGNhMGVkYTc2NDdhOGFiN2MyMDYxYzJlMTE4YTE4YTkzNmYxM2QweDMzYzFmZWZmYmY3MjE3ZDdiMjI0NGRjOTA1MWYwNGM0OTdhMDRhMDI1Nzc4IiwiRGF0YVR5cGUiOiJzdHJpbmcifSwibGFzdFVwZGF0ZWRUaW1lc3RhbXAiOnsiVmFsdWUiOiIxNjkyOTE4MTc5IiwiRGF0YVR5cGUiOiJEYXRlVGltZSJ9fSwiUGFnaW5hdGlvbkRpcmVjdGlvbiI6Ik5FWFQifQ=="
    }
  ) {
    TokenBalance {
      owner {
        identity
      }
    }
    pageInfo {
      hasNextPage
      hasPrevPage
      nextCursor
      prevCursor
    }
  }
}

Developer Support

If you have any questions or need help regarding how cursor pagination work, please join our Airstack's Telegram group.

More Resources

Last updated

Was this helpful?