Lightspark
Lightspark

Pagination

When you try to access a list of objects (for example the nodes that belong to an account), you will receive a Connection object. Connections expose metadata about the objects in the list, without loading all those objects, and will enable the client to paginate properly.
You can fetch a maximal amount of 200 entities in a single request. You should only fetch the items you need to display on the screen and implement a "load more" mechanism if you want to give access to more items.

Connections

After instantiating a client, you can create a connection and access its objects by getting the entities.
const account = client.getCurrentAccount();
const connection = account.getTransactions(
    client,
    /* first */ 20
);

console.log(`The total number of transactions is ${connection.count}.`);

// Let's print the IDs for the current page (the first 20 transactions)
for (const transaction of connection.entities) {
    console.log(`Transaction ID = ${transaction.id}.`);
}
If you want to get the next page, you can use the PageInfo object to iterate on the connection. entities will always contain the objects from the current page.
const MAX_ITERATIONS = 10;
let numIterations = 1;
while (connection.pageInfo.hasNextPage && numIterations < MAX_ITERATIONS) {
    console.log("Fetching the following page.");
    numIterations++;
    const connection = account.getTransactions(
        client,
        /* first */ 20,
        /* after */ connection.pageInfo.endCursor
    );
    for (const transaction of connection.entities) {
        console.log(`Transaction ID = ${transaction.id}.`);
    }
}
console.log("Everything was loaded!");
The GraphQL API exposes the connection as AccountToNodesConnection.
type AccountToNodesConnection {
  """The total count of objects in the connection."""
  count: Int!

  """The pagination information for this request (see below)."""
  page_info: PageInfo!

  """The objects you are requesting."""
  entities: [LightsparkNode!]!
}
The PageInfo object contains the following fields:
type PageInfo {
  """Do we have a page after this one in the result set?"""
  has_next_page: Boolean

  """Do we have a page before this one in the result set?"""
  has_previous_page: Boolean

  """The ID of the first element of the current page."""
  start_cursor: ID

  """The ID of the last element of the current page."""
  end_cursor: ID
}
If you need to query the number of nodes in an account, you can use the following query:
query Test {
  current_account {
    nodes {
      count
    }
  }
}
If you want to get the first 10 nodes and the pagination info:
query Test {
  current_account {
    nodes(first: 10) {
      entities {
        # This is a list of objects of type `LightsparkNode`
        id 
      }
      page_info {
        has_next_page
        end_cursor
      }
    }
  }
}
If you want to get the next page, you can use the PageInfo.end_cursor field:
query Test($end_cursor: ID!) {
  current_account {
    nodes(first: 10, after: $end_cursor) {
      entities {
        # This is a list of objects of type `LightsparkNode`
        id 
      }
    }
  }
}