Skip to main content
shoppy.products.after(cursor)
Sets the cursor for forward pagination. Use to fetch the next page.
This is a chainable method. Call .list() to execute.

Parameters

ParamTypeRequiredDescription
cursorstringYespageInfo.endCursor from previous response

Returns

ProductsQueryBuilder (chainable)

Examples

Basic pagination

// First page
const page1 = await shoppy.products.limit(12).list()

// Next page
if (page1.pageInfo.hasNextPage) {
    const page2 = await shoppy.products
        .limit(12)
        .after(page1.pageInfo.endCursor)
        .list()
}

Paginate collection

const page1 = await shoppy.products.collection('all').limit(12).list()

const page2 = await shoppy.products
    .collection('all')
    .limit(12)
    .after(page1.pageInfo.endCursor)
    .list()

Load all products

async function loadAll() {
    const all = []
    let cursor = null
    let hasMore = true

    while (hasMore) {
        const query = shoppy.products.limit(100)
        if (cursor) query.after(cursor)

        const { items, pageInfo } = await query.list()

        all.push(...items)
        hasMore = pageInfo.hasNextPage
        cursor = pageInfo.endCursor
    }

    return all
}