From 3634c06f916d7d852a48cd8d778f7ab7053fb17a Mon Sep 17 00:00:00 2001 From: James Rotering Date: Tue, 5 Dec 2023 13:07:16 -0600 Subject: [PATCH] Adds an extra item to posts_per_page to ensure that the total number of items in the query remain greater than the number asked for even when one is removed as a duplicate. Adds explicit order=ASC to graphql_cursor_compare_fields. Together these changes fix a bug where hasNextPage was wrongly returning false in wpgraphql when there should be a next page of results. --- includes/data/connection/class-event-connection-resolver.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/data/connection/class-event-connection-resolver.php b/includes/data/connection/class-event-connection-resolver.php index a0158e01..9fa0083f 100644 --- a/includes/data/connection/class-event-connection-resolver.php +++ b/includes/data/connection/class-event-connection-resolver.php @@ -106,7 +106,7 @@ public function get_query_args() { /** * Set posts_per_page the highest value of $first and $last, with a (filterable) max of 100 */ - $query_args['posts_per_page'] = $this->one_to_one ? 1 : min( max( absint( $first ), absint( $last ), 10 ), $this->query_amount ) + 1; + $query_args['posts_per_page'] = $this->one_to_one ? 1 : min( max( absint( $first ), absint( $last ), 10 ), $this->query_amount ) + 2; // set the graphql cursor args. $query_args['graphql_cursor_compare'] = ( ! empty( $last ) ) ? '>' : '<'; @@ -135,6 +135,7 @@ public function get_query_args() { 'key' => Occurrences::table_name() . '.start_date_utc', 'value' => $cursor_node->start_date_utc, 'type' => 'DATETIME', + 'order' => 'ASC' ], ];