#897 - Cursor pagination does not preserve order with the "search" where arg#898
Merged
jasonbahl merged 2 commits intoJul 10, 2019
Conversation
…search" where arg WP_Query applies default ordering by title when the "s" arg is passed to it, which was causing funky issues with WPGraphQL Cursor Pagination. This sets the `search_orderby_title` to false, and defaults to orderby date. Custom orderby options can be passed to the connection as well.
hughdevore
reviewed
Jul 10, 2019
hughdevore
approved these changes
Jul 10, 2019
hughdevore
left a comment
Contributor
There was a problem hiding this comment.
Good stuff, just a couple extra spaces
| $this->compare_with( $by, $order ); | ||
| } | ||
| } else if ( ! empty( $orderby ) && is_string( $orderby ) ) { | ||
|
|
| $orderby = $this->get_query_var( 'orderby' ); | ||
| $order = $this->get_query_var( 'order' ); | ||
|
|
||
|
|
…search" where arg - Formatting changes
Codecov Report
@@ Coverage Diff @@
## develop #898 +/- ##
==========================================
- Coverage 60.83% 60.8% -0.04%
==========================================
Files 132 132
Lines 7795 7809 +14
==========================================
+ Hits 4742 4748 +6
- Misses 3053 3061 +8
Continue to review full report at Codecov.
|
t0lya
reviewed
Jul 10, 2019
| $this->app_info = new \GraphQL\Type\Definition\ResolveInfo( array() ); | ||
|
|
||
| $this->query = ' | ||
| query GET_POSTS($first: Int, $last: Int, $after: String, $before: String $where:RootQueryToPostConnectionWhereArgs) { |
Contributor
There was a problem hiding this comment.
@jasonbahl seems like a comma is missing before the where arg
Collaborator
Author
There was a problem hiding this comment.
good call. Commas in variable declarations are optional, so not a big deal, but probably should adjust for consistency 😄
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.
WP_Query applies default ordering by title when the "s" arg is passed to it, which was causing funky issues with WPGraphQL Cursor Pagination.
This sets the
search_orderby_titleto false, and defaults to orderby date. Custom orderby options can be passed to the connection as well.Does this close any currently open issues?
#897
Any relevant logs, error output, GraphiQL screenshots, etc?
To test, I created 4 posts with the word "floof" as the content.
In the admin, you can see a search for "floof" shows posts: `Four, Three, Two, One"
Query the last 2
Here, I query for the
last: 2items, and as expected, we get PostsTwoandOne.Query
Variables
{ "last": 2, "before": "YXJyYXljb25uZWN0aW9uOjEzOTc=", "where": { "search": "floof" } }Screenshot of results
Query with before cursor
Now, if we execute the same query, but use the
startCursorfrom the previous query results as the value for thebeforeinput we get itemsFourandThree:Variables
{ "last": 2, "before": "YXJyYXljb25uZWN0aW9uOjEzOTc=", "where": { "search": "floof" } }Screenshot of paginated query
Any other comments
Tests are included for forward and backward pagination using the
{where: { search: ""} }argumentWhere has this been tested?
Operating System: Mac OSX 10.14.5
WordPress Version: WordPress v5.2.2