adobe / aem-headless-client-js

AEM Headless Client for JavaScript
Apache License 2.0
25 stars 12 forks source link

Feature/#25 pagination #44

Closed easingthemes closed 1 year ago

easingthemes commented 1 year ago

Closes https://github.com/adobe/aem-headless-client-js/issues/25

easingthemes commented 1 year ago

Example usage

(async () => {
    const model = 'article'
    const fields = `{
        title
        _path
        authorFragment {
          firstName
          profilePicture {
            ...on ImageRef {
              _authorUrl
            }
          }
        }
      }`

    // Cursor based: Loop all pages
    const cursorQueryAll = await aemHeadlessClient.runPaginatedQuery(model, { pageSize: 3 }, fields)
    for await (let value of cursorQueryAll) {
        console.log('cursorQueryAll', value)
    }
    // Cursor based: Manually get next page
    const cursorQuery = await aemHeadlessClient.runPaginatedQuery(model, { pageSize: 4 }, fields)
    while (true) {
        const { done, value } = await cursorQuery.next();
        if (done) break
        console.log('cursorQuery', value)
    }
})()
Screenshot 2023-03-15 at 00 59 11
stefangrimm commented 1 year ago

I can't really go into the details, as I'm not very familiar with "modern JavaScript", but the general usage patterns look pretty good to me.