js-buy-sdk: [1.0beta] client.fetchNextPage() gives TypeError

I am trying to use fetchNextPage() to get the next page of products, but getting the following error:

TypeError: Cannot read property 'shop' of undefined
    at index.js:1998
    at Array.reduce (<anonymous>)
    at index.js:1997
    at <anonymous>

This is line 1997-1999 that is being referred to:

response.model = path.reduce(function (object, key) {
    return object[key];
}, response.model);

Here is my (reduced) use case:

const firstProduct = await client.product.fetchAll(1)
const secondProduct = await client.fetchNextPage(firstProduct)

firstProduct works fine, but secondProduct gives the TypeError.

Apologies if this is caused by my own mistake, I’m not 100% sure if I’m using the function correctly, and couldn’t figure out what was causing the error based on the source code.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 26 (11 by maintainers)

Most upvoted comments

As I said above: working on a fix.

Yep same issue, except I’m getting Cannot read property 'node' of undefined.

This is hopefully fixed in #435 through the fix added in https://github.com/Shopify/graphql-js-client/pull/99. As soon as #435 goes in, I’ll release a new beta.