wp-graphql-woocommerce
wp-graphql-woocommerce copied to clipboard
Issue with cursor pagination, some woocommerce products are skipped
Description: I'm trying to use cursor pagination to load woocommerce products using wpgraphql. It works fine but it skips some products. E.g I have 232 published products. With rest api using offset pagination it works fine and loads everything, with wpgraphql however it skips some. Some of the products are published with same date. That could be an issue? I'm expecting to load all products without some being skipped.
I'm doing the query like this in IDE:
query GET_PRODUCTS_BASIC {
products(
before: null
after: null
last: null
first: 20
) {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
nodes {
menuOrder
name
date
}
}
}
The results I receive are these:
[
{
"menuOrder": 0,
"name": "Flexifit Modal Vest",
"date": "2021-11-17T13:36:05+00:00"
},
{
"menuOrder": 0,
"name": "Flexifit Modal Vest",
"date": "2021-11-17T13:36:04+00:00"
},
{
"menuOrder": 0,
"name": "3 Pack Glass Percy Pig Baubles",
"date": "2021-11-16T18:01:25+00:00"
},
{
"menuOrder": 0,
"name": "2pk Cotton Percy Pig Slipper Socks",
"date": "2021-11-16T18:01:21+00:00"
},
{
"menuOrder": 0,
"name": "Glitter heel shoes pink",
"date": "2021-11-12T12:14:18+00:00"
},
{
"menuOrder": 0,
"name": "PURE FIT-SLIP, WHITE",
"date": "2021-11-11T13:32:42+00:00"
},
{
"menuOrder": 0,
"name": "CUPIZ BANDEAU, WHITE",
"date": "2021-11-05T09:35:19+00:00"
},
{
"menuOrder": 0,
"name": "Viscose v-neck sweater",
"date": "2021-10-13T10:39:10+00:00"
},
{
"menuOrder": 0,
"name": "Kylie drawstring backpack black",
"date": "2021-10-13T10:38:53+00:00"
},
{
"menuOrder": 0,
"name": "Glitter mule slippers pink",
"date": "2021-10-13T10:38:50+00:00"
},
{
"menuOrder": 0,
"name": "Country retreat twist stone earrings blue",
"date": "2021-10-13T10:38:47+00:00"
},
{
"menuOrder": 0,
"name": "Frill bow back coat pink",
"date": "2021-10-13T10:38:40+00:00"
},
{
"menuOrder": 0,
"name": "Christmas party gloves multi",
"date": "2021-10-13T10:38:38+00:00"
},
{
"menuOrder": 0,
"name": "Becca quilted gym bag",
"date": "2021-10-13T10:38:37+00:00"
},
{
"menuOrder": 0,
"name": "Purple missguided side split tracksuit joggers",
"date": "2021-10-13T10:38:33+00:00"
},
{
"menuOrder": 0,
"name": "Grey acid wash msgd sports cropped t shirt",
"date": "2021-10-13T10:38:30+00:00"
},
{
"menuOrder": 0,
"name": "Sand bubble sole trainers",
"date": "2021-10-13T10:38:28+00:00"
},
{
"menuOrder": 0,
"name": "Leather Reversible Belt",
"date": "2021-06-15T11:47:58+00:00"
},
{
"menuOrder": 0,
"name": "Cotton Technical Mac with Stormwear",
"date": "2021-06-15T11:39:39+00:00"
},
{
"menuOrder": 0,
"name": "SHORTSLEEVESTSHIRT",
"date": "2021-06-15T11:39:38+00:00"
}
]
SHORTSLEEVESTSHIRT is in not in 20th place as the wordpress admin is showing and one item is skipped. If I continue using the cursor pagination to move forward more products are skipped. Worths mentioning that menuOrder always returns 0.
Is there any solution to this?
WPGraphQL Version: 1.8.0 WordPress version: 5.9.3 WooCommerce version: 6.3.1
Other plugins I'm using: WPGraphQL for Advanced Custom Fields WPGraphQL WooCommerce (WooGraphQL) - v.0.11.0 Add WPGraphQL SEO ACF to REST API Advanced Custom Fields PRO WP REST Cache WP-Optimize - Clean, Compress, Cache WP-REST-API V2 Menus
UPDATE: I noticed that some products had menu_order other than 0. That seemed to be the reason of this cause. I'm testing again to be sure but by executing this sql query to set all products menu_order to zero seemed to have fixed it.
UPDATE wp_posts SET menu_order=0 WHERE post_type="product" AND post_status="publish";
Steps to reproduce:
- Add manually to some woocommerce products some
menu_ordervalue other than0, could benullor different number - Then try to query products with wpgraphql IDE.
- Use cursor pagination with
after: endcursorsto check all products. You will see that all products with menu_order other than 0 are skipped.
Potential fix is to set all products menu_order to 0 using this sql query:
UPDATE wp_posts SET menu_order=0 WHERE post_type="product" AND post_status="publish";
@alexkey89 Is there still an issue here?
@kidunot89 Apparently there is in case the menu_order of products is other than 0. To fix this I had to manually set everything to 0 in the db directly with this sql query: UPDATE wp_posts SET menu_order=0 WHERE post_type="product" AND post_status="publish";
Maybe the plugin itself can either do this automatically or have an option to do it?
Closing. Issue was resolved in v0.12.1