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

Product Query with Reverse Pagination and Orderby #843

Open
MonPetitUd opened this issue Apr 2, 2024 · 0 comments
Open

Product Query with Reverse Pagination and Orderby #843

MonPetitUd opened this issue Apr 2, 2024 · 0 comments

Comments

@MonPetitUd
Copy link

Describe the bug
When querying products with "last", "before" and "orderby" inputs the returned products are not as expected.

To Reproduce
Initial query to get some products and pageInfo...

query products {
	products(first: 5, where: { status: "PUBLISHED" , orderby: [ { field: NAME, order: ASC }]} ) {
		edges {
			cursor
			node {
				id 
				name
			}
		}
		pageInfo {
			startCursor
			endCursor
			hasNextPage
			hasPreviousPage
		}
	}
}

Using the "endCursor" from this query as the "after" input the following query we get the next 5 products...

query productsForward {
	products(first: 5, after: "YXJyYXljb25uZWN0aW9uOjc4Nw==", where: { status: "PUBLISHED" , orderby: [ { field: NAME, order: ASC }]} ) {
		edges {
			cursor
			node {
				id 
				name
			}
		}
		pageInfo {
			startCursor
			endCursor
			hasNextPage
			hasPreviousPage
		}
	}
}

Using the "startCursor" from the "productsForward" pageInfo result in the "before" input we try to go back... but we get unexpected resulting products in a strange order.

query productsBackward {
	products(last: 5, before: "YXJyYXljb25uZWN0aW9uOjMwMTE=", where: { status: "PUBLISHED" , orderby: [ { field: NAME, order: ASC }]} ) {
		edges {
			cursor
			node {
				id 
				name
			}
		}
		pageInfo {
			startCursor
			endCursor
			hasNextPage
			hasPreviousPage
		}
	}
}

Expected behavior
Given the provided inputs "productsBackward" query should return the same products as the initial "products" query. If we omit the "orderby" input in all the above queries everything appears to work as expected.

Plugin Versions

  • WooGraphQL Version: 0.19.0
  • WPGraphQL Version: 1.22.1
  • WordPress Version: 6.4.3
  • WooCommerce Version: 8.6.1

Additional context
I could be doing it wrong :)

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