My Products
Help
omelhus
PARTNER

Issue with hasNextPage when using groupBy

by omelhus

Hey,

 

So there seems to be an issue with pagination when using groupBy and aggregations. The following query returns 75 records and hasNextPage: true, and an endCursor, but when I try to follow the end cursor it returns a database error.

The numeric value of the endCursor is interestingly enough 68, even though the query returns 75 records.

 

query GroupStockBalanceByProduct($cid: Int!, $excludeStock: [Int!], $after: String = null) {
  useCompany(no: $cid) {
    stockBalance(
      filter: {warehouseNo: {_not_in: $excludeStock}},
      groupBy: [{productNo: DEFAULT}],
      after: $after
    ) {
      totalCount
      pageInfo {
        hasNextPage
        endCursor
      }
      items {
        productNo
        aggregates {
          sum {
            realisedStock
            unrealisedStockIncrease
            reservedFromStock
            inHireOrder
            inLoanOrder
            inOrder
            inOrderToProduction
            inProduction
            inPurchase
          }
        }
      }
    }
  }
}

 

Error response

 

{
  "errors": [
    {
      "message": "Error: SQL command no. 3010 failed.Database error.",
      "extensions": {
        "data": {
          "status": 2,
          "status_name": "DatabaseError"
        }
      }
    }
  ],
  "data": {
    "useCompany": {
      "stockBalance": {
        "totalCount": 75,
        "pageInfo": {
          "hasNextPage": false,
          "endCursor": null
        },
        "items": null
      }
    }
  },
  "extensions": {
    "vbnxt-trace-id": "00000000000000001c430aae153278be"
  }
}
1 REPLY 1
Accepted solution
omelhus
PARTNER

by omelhus

Well, I just read the docs properly. Suggesting setting hasNextPage to false for grouped queries.

 

omelhus_0-1707827618339.png