Loading more than a 100 entries

I'm problems with loading more than a 100 entries.

I dispatching an action in nuxtInitServer, that calls a async method with a do while loop that increments the page number and return the data

 const getPages = async (context) => {
  const data = []
  let pageNum = 1
  let lastResult = []

  do {
    const resp = await context.$prismic.api.query(
      context.$prismic.predicates.at('document.type', 'artists'),
        pageSize: 100,
        page: pageNum
    lastResult = resp


  } while (lastResult.next_page !== null)

  return data

But when I run "npm run generate" I get this error for some of my subpages.

FetchError: request to https://rtt2020.cdn.prismic.io/api/v2/documents/search?&page=1&pageSize=1&ref=X7KK4xIAACAAeYOk&q=%5B%5Bat(document.type%2C%20%22globals%22)%5D%5D failed, reason: read ECONNRESET
    at ClientRequest.<anonymous> (/Users/kristianjohansen/Sites/rtt2020.nuxt/node_modules/cross-fetch/node_modules/node-fetch/lib/index.js:1461:11)
    at ClientRequest.emit (events.js:314:20)
    at ClientRequest.EventEmitter.emit (domain.js:486:12)
    at TLSSocket.socketErrorListener (_http_client.js:469:9)
    at TLSSocket.emit (events.js:314:20)
    at TLSSocket.EventEmitter.emit (domain.js:486:12)
    at emitErrorNT (internal/streams/destroy.js:100:8)
    at emitErrorCloseNT (internal/streams/destroy.js:68:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)

If I only load the first 100 it works. So guess there is something wrong with the function. Anyone knows how to load more than a 100 results?

Many thanks!

Hey Kristian,

Thanks for posting this question! When I tested your function, I get an array of arrays. Here's the result of getPages() I get when I query all documents on a repo with 475 items:

However, it worked perfectly when I spread resp.results before pushing it to data:

lastResult = resp


Let me know if that changes anything. If not, could you zip your project and send it to me, or share your GitHub repo, and also your Prismic repo name? (In a DM if you like).


Thanks, @kristian! I got the DM with your info. I tried debugging this myself. I got the same errors, and couldn't figure them out. I'm not sure if it's a problem with your function. I was able to get all 185 documents using your function (with the spread operator) just fine. It seems to me like the error happens after the function runs — though I can't be sure.

I've escalated this issue to our dev team, and I'll let you know what I hear back.


Thanks very much Sam! I'm looking forward to hear back..

And thanks for an amazing product!

1 Like

Hey Sam, I hope you had a good weekend.

Just want to check in if you have heard back from the dev team on this matter?


Hey Kristian,

No word yet, but I'll send a message to follow-up.