Bugfix/taxonomy pagination#2410
Merged
jasonbahl merged 3 commits intowp-graphql:developfrom Jun 21, 2022
Merged
Conversation
|
Code Climate has analyzed commit 49bd6d1 and detected 0 issues on this pull request. View more on Code Climate. |
justlevine
reviewed
Jun 20, 2022
Collaborator
There was a problem hiding this comment.
Looks good over here 🔥
(For posterity: this works by overloading AbstractConnectionResolver's methods to fix regressions in TaxonomyConnectionResolver only. Once the actual causes are addressed in the parent class - as these same pagination issues affect other connections - , much of this code can probably be removed.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this implement/fix? Explain your changes.
This fixes a bug with taxonomy pagination where the end cursor wasn't properly being respected for subsequent paginated requests.
Does this close any currently open issues?
closes #2343
Any other comments?
With the following snippet I've registered a taxonomy for every letter of the alphabet.
So we end up with the following list of taxonomies:
{ "category": "category", "post_tag": "post_tag", "post_format": "post_format", "A": "A", "B": "B", "C": "C", "D": "D", "E": "E", "F": "F", "G": "G", "H": "H", "I": "I", "J": "J", "K": "K", "L": "L", "M": "M", "N": "N", "O": "O", "P": "P", "Q": "Q", "R": "R", "S": "S", "T": "T", "U": "U", "V": "V", "W": "W", "X": "X", "Y": "Y", "Z": "Z" }I can then make a query for a set of these taxonomies like so:
with variables:
{ "first": 5 }and we should expect to get the first 5 taxonomies in response:
We can see this working as expected.
Then, we should be able to take the
pageInfo.endCursorvalue and use it as the input value for theaftervariable to query the next page.Like so:
{ "first": 5, "after": "YXJyYXljb25uZWN0aW9uOkI=" }This is where the bug was happening.
We should expect nodes (the first 5 nodes after node "B"):
BEFORE
Before this PR, we would get the following output:
{ "data": { "taxonomies": { "pageInfo": { "endCursor": "YXJyYXljb25uZWN0aW9uOkM=", "hasNextPage": true, "hasPreviousPage": true, "startCursor": "YXJyYXljb25uZWN0aW9uOnBvc3RfdGFn" }, "nodes": [ { "id": "dGF4b25vbXk6cG9zdF90YWc=", "name": "post_tag" }, { "id": "dGF4b25vbXk6cG9zdF9mb3JtYXQ=", "name": "post_format" }, { "id": "dGF4b25vbXk6QQ==", "name": "A" }, { "id": "dGF4b25vbXk6Qg==", "name": "B" }, { "id": "dGF4b25vbXk6Qw==", "name": "C" } ] } }, }This is not what we want!
AFTER
After this PR, the same query returns the following:
{ "data": { "taxonomies": { "pageInfo": { "endCursor": "YXJyYXljb25uZWN0aW9uOkc=", "hasNextPage": true, "hasPreviousPage": false, "startCursor": "YXJyYXljb25uZWN0aW9uOkM=" }, "nodes": [ { "id": "dGF4b25vbXk6Qw==", "name": "C" }, { "id": "dGF4b25vbXk6RA==", "name": "D" }, { "id": "dGF4b25vbXk6RQ==", "name": "E" }, { "id": "dGF4b25vbXk6Rg==", "name": "F" }, { "id": "dGF4b25vbXk6Rw==", "name": "G" } ] } }, }This is what we were expecting! 🥳 🎉
We can take the end cursor (for node "G") and do another request, expecting nodes "H" through "L"
And we see we get the expected results:
{ "data": { "taxonomies": { "pageInfo": { "endCursor": "YXJyYXljb25uZWN0aW9uOkw=", "hasNextPage": true, "hasPreviousPage": false, "startCursor": "YXJyYXljb25uZWN0aW9uOkg=" }, "nodes": [ { "id": "dGF4b25vbXk6SA==", "name": "H" }, { "id": "dGF4b25vbXk6SQ==", "name": "I" }, { "id": "dGF4b25vbXk6Sg==", "name": "J" }, { "id": "dGF4b25vbXk6Sw==", "name": "K" }, { "id": "dGF4b25vbXk6TA==", "name": "L" } ] } }, }