wp-graphql / wp-graphql-woocommerce

Add WooCommerce support and functionality to your WPGraphQL server
https://woographql.com
GNU General Public License v3.0
649 stars 130 forks source link

Setting amount of products in pagination not working #827

Open YishaqG opened 11 months ago

YishaqG commented 11 months ago

Describe the bug Using query products setting first misbehaves not always returns the requested amount of elements.

To Reproduce

  1. Query products with first > 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

YishaqG commented 10 months ago

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": []
    }
  }
}
claudio-uey commented 10 months ago

Same issue here

claudio-uey commented 10 months ago

Any update on this issue?

kpoelhekke commented 8 months ago

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.

MonPetitUd commented 8 months ago

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.

kidunot89 commented 6 months ago

@MonPetitUd @kpoelhekke @claudio-uey @YishaqG Do you guys have Enable Unsupported Types setting activated? Does it make a difference in the result count?

MonPetitUd commented 6 months ago

@kidunot89 I don't be that setting was enabled when I encountered this issue.

kpoelhekke commented 6 months ago

@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.

kpoelhekke commented 5 months ago

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.