Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation on pagination #386

Closed
doublerebel opened this issue Jul 10, 2017 · 1 comment
Closed

Documentation on pagination #386

doublerebel opened this issue Jul 10, 2017 · 1 comment

Comments

@doublerebel
Copy link
Contributor

doublerebel commented Jul 10, 2017

Hello,

Is there official documentation for pagination? I have read in #221 and #369 that total count is not available, but it took me quite a while to realize that fetchAllProducts doesn't actually fetch all products, just the first 20 and the rest are paginated. There is a lot of discussion about fetching in #148 but I'm not sure if that is current with 1.0alpha.

  • Are all sets paginated?
  • Is it the same number per page for all sets (20)?
  • Is this the correct way to page through a set?
var products = await shopify.fetchAllProducts()
// products contains up to 20 products

var moreProducts = await client.graphQLClient.fetchNextPage(products)
// moreProducts.model contains next page of up to 20 products starting at #21

Pagination added in #300 and #314 gave me the first clue, but there is no pagination in the shopify-buy library (P.S. developing and publishing on alpha branch and not master makes it difficult to search the code without downloading the whole library source).

So I inspected the products and the product items are actually a GraphModel. Googling for GraphModel gives me an empty doc but on the GraphModel objects are a function nextPageQueryAndPath. Google only shows a single result for nextPageQueryAndPath, the source to the GraphQL client, where luckily I found fetchNextPage. fetchNextPage seems to work fine.

Thanks!

@minasmart
Copy link
Contributor

GraphModel is empty by design. It's extendable, but it's mostly an object proxy. v1 of Shopify Buy is really just a thin layer on top of our graphql client, and our storefront API. Pagination, at the API level, uses the relay connection specification, which is wrapped up nicely by graphql-js-client using fetchNextPage (part way down the page). There's also an example here. We absolutely need a better way to expose pagination at the top level of this library, but until then, your approach is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants