The Query Object

The Query object is returned every time you request a collection of items. It contains the requested data and some helpful properties and methods.

Retrieving the data

You can access the requested data under Query object’s properties.

const videos = await client.fetchVideos();

console.log(videos.items);                      // The returned list of videos.
console.log(videos.pageInfo.hasNextPage);       // true
console.log(videos.hasNextPage);                // Shortcut for the above
console.log(videos.pageInfo.hasPreviousPage);   // false
console.log(videos.pageInfo.startCursor);       // Cursor property of the first item on the most recent page.
console.log(videos.pageInfo.endCursor);         // Cursor property of the last item on the most recent page.
console.log(videos.totalCount);                 // Total count of objects available.
console.log(videos.isFetching);                 // Is the query currently fetching?

Fetching more data

The Query objects has the ability to fetch more items from the API using the fetchMore method.

const videos = await client.fetchVideos();

console.log(videos.items.length);   // 20

await videos.fetchMore();

console.log(videos.items.length);   // 40