-
Notifications
You must be signed in to change notification settings - Fork 279
Ensure endCursor is NULL when hasNextPage is FALSE in GraphQL response #2121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure endCursor is NULL when hasNextPage is FALSE in GraphQL response #2121
Conversation
can you show example of contents of last page before and after your change? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few questions. Can you also point out in PR description some test that exercise pagination to the last page? so we can look locally to see what the response contents as a result of this change?
src/Service.Tests/SqlTests/GraphQLPaginationTests/GraphQLPaginationTestBase.cs
Show resolved
Hide resolved
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to prevent the regression introduced and add a test to protect against it.
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
for your pr description:
do you mean that "this logic" for adding to the limit() value is excluded when both Does this change look to affect REST API at all, with your latest commits? Would be good to include a copy/paste of the example request/response for this:
|
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
Yes, I added that to the PR description now to be more clear.
No. Nothing on the REST side is changing.
Included! |
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
src/Service.Tests/SqlTests/GraphQLPaginationTests/MySqlGraphQLPaginationTests.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for making these changes, adding tests for coverage of both bugs identified and having pr description outlining all context and before/after
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making these changes. This will help bring consistency in the value of endCursor
across Cosmos and SQL database types, GraphQL and REST.
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
connection issue caused test to fail, re-running |
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
Why make this change?
Closes #2030
Closes #2130
Fixes a bug where we would have a
non null
endCursor
in GraphQL responses, despitehasNextPage
being false. In other words, providing a bookmark to the next page of results when no such page exists.And also, when we do not include
hasNextPage
but we are still on the last page,endCursor
should benull
.What is this change?
We now check if we have an extra element or not before we create the
endCursor
. We define having a next page of results as having an extra element in the result set that is returned from our query. This is because when we make a paginated query we add 1 to our limit, that way we can tell if there is another page of results based on if that extra element returns or not. We now include this logic if eitherhasNextPage
, orendCursor
is in the request so that we will correctly follow the logic for any pagination scenario. That means adding 1 to the limit and checking if there is another page of records beyond the number in the request.How was this tested?
Updated the pagination tests to have null
endCursor
expected whenhasNextPage
is false.Added cases to the
RequestAfterTokenOnly
test cases to include both being on the final page and not, this verifies we get a correctly builtnon null
and correctly builtnull
endCursor
for those respective cases.Sample Request(s)
Before the fix, this request would result in a response that would include an endCursor to a page that does not exist.
W3siRW50aXR5TmFtZSI6IlJldmlldyIsIkZpZWxkTmFtZSI6ImJvb2tfaWQiLCJGaWVsZFZhbHVlIjoxLCJEaXJlY3Rpb24iOjB9LHsiRW50aXR5TmFtZSI6IlJldmlldyIsIkZpZWxkTmFtZSI6ImlkIiwiRmllbGRWYWx1ZSI6NTY5LCJEaXJlY3Rpb24iOjB9XQ==
decodes to[{"EntityName":"Review","FieldName":"book_id","FieldValue":1,"Direction":0},{"EntityName":"Review","FieldName":"id","FieldValue":569,"Direction":0}]
and if we look at the data in our table we can see that an endCursor that indicates the next page of data starts after id=569 will not be providing a link to a page at all as there are no more records after id=569After adding this fix we can see that instead we will have a null endCursor, as expected
Similar behavior can be seen for only request an
endCursor
but not includinghasNextPage
. If you simply removehasNextPage
from the above requests, you will see the same inconsistent behavior before the fix, and the same consistency now after the fix.So looking at the request
Before the fix we would see
But after the fix we have