My Products
Help
Florian Haase
PARTNER

HasNextPage

by Florian Haase

Hi,

 

I thought that the returnvalue from the API "hasNextPage" indicates if there is a next page?

 

{query : useCompany(no: 4655191)
{associate(filter:{changedDateTime: {_gte:"2023-06-07T07:33:00.000"}}
after:"Ng==", first: 1) {pageInfo{hasNextPage endCursor}
items{name shortName employeeNo customerNo supplierNo employeeNo associateNo
changedDateTime createdDateTime addressLine1 addressLine2 companyNo
euVatRegistrationNo customerPriceGroup1 customerPriceGroup2 customerPriceGroup3 countryNo postCode postalArea languageNo}}}}

 results in:

{
"data": {
"query": {
"associate": {
"pageInfo": {
"hasNextPage": true,
"endCursor": "Nw=="
},
"items": [
{
"name": "lars",
"shortName": "lars",
"employeeNo": 0,
"customerNo": 0,
"supplierNo": 0,
"associateNo": 33147,
"changedDateTime": "2023-06-07T07:37:00",
"createdDateTime": "2023-06-07T07:37:00",
"addressLine1": "",
"addressLine2": "",
"companyNo": "",
"euVatRegistrationNo": "",
"customerPriceGroup1": 0,
"customerPriceGroup2": 0,
"customerPriceGroup3": 0,
"countryNo": 0,
"postCode": "",
"postalArea": "",
"languageNo": 0
}
]
}
}
},
"extensions": {
"vbnxt-trace-id": "000000000000000034350908720dad17"
}
}

So getting the next page should have a result?

{query : useCompany(no: 4655191){associate(filter:
{changedDateTime: {_gte:"2023-06-07T07:33:00.000"}}
after:"Nw==", first: 1) {pageInfo{hasNextPage endCursor}
items{name shortName employeeNo customerNo supplierNo employeeNo
associateNo changedDateTime createdDateTime addressLine1 addressLine2
companyNo euVatRegistrationNo customerPriceGroup1 customerPriceGroup2
customerPriceGroup3 countryNo postCode postalArea languageNo}}}}

results in a empty page:



{
"data": {
"query": {
"associate": {
"pageInfo": {
"hasNextPage": false,
"endCursor": null
},
"items": null
}
}
},
"extensions": {
"vbnxt-trace-id": "0000000000000000ab879fc8f40165b7"
}
}

 In combination of using Azure Datafactory with that it results in a endless-loop which makes Microsoft very happy about the cost/usage. (because Datafactory don't write data on empty pages and than we never get the information that the next page would not exist and we continue about asking this empty page)

 

Florian

6 REPLIES 6
Accepted solution
Marius Bancila
VISMA

by Marius Bancila

A fix for this is in production. hasNextPage should now return the correct value in all cases.

by Marius Bancila (Updated ‎22-06-2023 17:07 by Marius Bancila VISMA )

I understand your concern and frustration. It's my fault for not documenting this properly. hasNextPage is not exhaustive but rather a hint that sometimes provides false positives. hasPreviousPage should work correctly. But for hasNextPage to always return the correct result we would have to retrieve the count of (filtered) rows from the backend which we don't do currently. So if you ask for N records but get < N, then it will properly tell you that there is no next page. But if you get exactly N, it will say there is a next page. However, fetching for the next page should return an empty set. I understand that is a request too many that incurs costs, but it shouldn't generate an infinite loop (like you seemed to suggest). We will investigate how to improve this.

SvenTore
CONTRIBUTOR **

by SvenTore

You can solve this by internally trying to fetch pageSize+1 record, and if you get pageSize+1, then you drop the last record and know there is a next page. It's in most cases munch less expensive than doing a total count, but will still have a correct info about more pages. 
With current implementation it's much better to not have a hasNextPage, since API users should never use it. They would all need to implement counting in the client or use the page+1 trick on the client if app does not need all pages at once

omelhus
PARTNER

by omelhus

You can also do Number(base64decode(endCursor)) == totalCount, but I know a lead dev that won't be too happy about that.

 

I'm doing it though.

Florian Haase
PARTNER

by Florian Haase

Yes, of course, that's also possible. Thank you. But if this could be fixed maybe others won't spent time on finding solutions around the problem 🙂

Florian Haase
PARTNER

by Florian Haase

And: no stress, I get solved this by checking the number of rows in the result instead, but the hasNextPage is useless