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

The pagination is not working as expected. The endCursor returns same value for each new query request to the Shopify. #2016

Closed
4 of 5 tasks
dani-sanomads opened this issue Jan 24, 2025 · 1 comment

Comments

@dani-sanomads
Copy link

dani-sanomads commented Jan 24, 2025

Issue summary

Before opening this issue, I have:

  • Upgraded to the latest version of the relevant packages
    • @shopify/[email protected] package and version:
    • Node version: v22.3.0
    • Operating system: Mac OS 15.1.1 (24B91)
  • Set { logger: { level: LogSeverity.Debug } } in my configuration, when applicable
  • Found a reliable way to reproduce the problem that indicates it's a problem with the package
  • Looked for similar issues in this repository
  • Checked that this isn't an issue with a Shopify API

We are using the following @shopify/[email protected] version. We are not able to fetch all productVariants from Shopify while using the pagination as mentioned in the dev-docs.

Expected behavior

What do you think should happen?

The endCursor should be different for each iteration. The hasNextPage should return false at some point while getting the productVariant pages using the graphql query.

Actual behavior

What actually happens?

The endCursor is returning same value for each iteration. The hasNextPage always returns true while getting the productVariant pages using the graphql query.

Steps to reproduce the problem

  1. Query for getting the productVariants:
    query GetInventoryLevel($first: Int, $query: String, $quantities_name: [String!]!, $after: String, $location_id: ID!){ productVariants(first: $first, query: $query, after: $after, reverse: false) { edges{ cursor node{ id title displayName inventoryItem{ inventoryLevel(locationId: $location_id){ id quantities(names: $quantities_name){ name quantity } item{ id tracked } location{ id } } id locationsCount{ count } } } } pageInfo { hasPreviousPage hasNextPage startCursor endCursor } } }

  2. Getting the result:
    export const getVariantInventoryLevels = async (admin: any, variables: any) => { console.log( "==============GET VARIANT INVENTORY LEVELS==============", variables, ); const response = await admin.graphql(GET_VARIANT_INVENTORY_LEVELS, variables); const responseJson = await response.json(); return responseJson?.data; };

  3. Calling the graphql API:
    let response = await getVariantInventoryLevels(admin, { variables: { first: 2, query:sku:${sku} location_id:${selectedLocation?.value?.split("/")?.pop()}, quantities_name: ["available"], after: null, location_id: selectedLocation?.value, } });

Debug logs

In case of using while loop or recursive function to fetch all the productVariants using the above functions it runs infinitely because the endCursor value does not changes.

The following is the result of pageInfo object after the first graphql query call and the cursor values remains the same:
{
"hasPreviousPage": false,
"hasNextPage": true,
"startCursor": "eyJsYXN0X2lkIjo0OTQ5NjU0MzQ2MTY1NiwibGFzdF92YWx1ZSI6NDk0OTY1NDM0NjE2NTZ9",
"endCursor": "eyJsYXN0X2lkIjo0OTY3MzQyMzYxODMyOCwibGFzdF92YWx1ZSI6NDk2NzM0MjM2MTgzMjh9"
}



@dani-sanomads
Copy link
Author

The issue was related to the endCursor latest value. I was not passing accurate values to each query request.

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

1 participant