wp-graphql-woocommerce
wp-graphql-woocommerce copied to clipboard
Setting amount of products in pagination not working
Describe the bug
Using query products
setting first misbehaves not always returns the requested amount of elements.
To Reproduce
- Query
products
withfirst
> 10
Expected behavior Returns the set amount
Plugin Versions WooGraphQL Version: 0.18.3 WPGraphQL Version: 1.19.0 WordPress Version: 6.4.2 WooCommerce Version: 8.3.1
Just tested with v0.19.0 and having the same issue with pagination
Query:
products(first: 19) {
nodes {
databaseId
}
}
}
Response:
"data": {
"products": {
"nodes": [
{
"databaseId": 34738
},
{
"databaseId": 34732
},
{
"databaseId": 34731
},
{
"databaseId": 34727
},
{
"databaseId": 34711
},
{
"databaseId": 34710
},
{
"databaseId": 34709
},
{
"databaseId": 34708
},
{
"databaseId": 34707
},
{
"databaseId": 34696
},
{
"databaseId": 34695
},
{
"databaseId": 34694
},
{
"databaseId": 34693
},
{
"databaseId": 34692
},
{
"databaseId": 34687
},
{
"databaseId": 34686
},
{
"databaseId": 34684
}
]
}
},
"extensions": {
"debug": [],
"queryAnalyzer": {
"keys": "82302315334ebe38740cc222092d11bc4494c3b877822def18dc0fe76841bcac graphql:Query operation:NewQuery list:variableproduct list:externalproduct list:groupproduct list:simpleproduct list:simpleproductvariation",
"keysLength": 204,
"keysCount": 8,
"skippedKeys": "",
"skippedKeysSize": 0,
"skippedKeysCount": 0,
"skippedTypes": []
}
}
}
Same issue here
Any update on this issue?
I've been able to track this down to these lines of code:
$model = $this->get_node_by_id( $id );
if ( true === $this->is_valid_model( $model ) ) {
$nodes[ $id ] = $model;
}
here: \WPGraphQL\Data\Connection\AbstractConnectionResolver::get_nodes
Somehow some products aren't a valid model and those get filtered out. Unfortunately I haven't been able to figure out why. Hope this helps on finding a solution, I'm currently blocked from updating from 0.12.1
because of this.
I encountered something similar and found that unpublished products i.e. draft products were consuming the "first" limit but not actually being returned, adding where: { status: "PUBLISHED" } to the query seemed to do the trick for me.
@MonPetitUd @kpoelhekke @claudio-uey @YishaqG Do you guys have Enable Unsupported Types setting activated? Does it make a difference in the result count?
@kidunot89 I don't be that setting was enabled when I encountered this issue.
@kidunot89 here toggling that setting doesn't have any effect. The query:
query NewQuery {
products(first: 48, where: {typeIn: [GROUPED]}) {
edges {
node {
id
name
}
}
pageInfo {
offsetPagination {
total
}
}
}
}
returns 47 items with the setting on and off.
I found the culprit: there seem to be some grouped products in our webshop that don't have simple products attached to them. Because of that they are not a valid model and they are excluded from the results. So it's a problem that can be solved on our side.
Although I would expect that the is_valid_model
check would also affect the total results and the pagination. But that might be in issue with wp-graphql
itself.