diff --git a/includes/data/connection/class-coupon-connection-resolver.php b/includes/data/connection/class-coupon-connection-resolver.php index 083230b1..db534e26 100644 --- a/includes/data/connection/class-coupon-connection-resolver.php +++ b/includes/data/connection/class-coupon-connection-resolver.php @@ -116,20 +116,22 @@ public function get_query_args() { ]; /** - * Set the graphql_cursor_offset which is used by Config::graphql_wp_query_cursor_pagination_support - * to filter the WP_Query to support cursor pagination + * Set the cursor args. + * + * @see \WPGraphQL\Data\Config::graphql_wp_query_cursor_pagination_support */ - $cursor_offset = $this->get_offset(); - $query_args['graphql_cursor_offset'] = $cursor_offset; - $query_args['graphql_cursor_compare'] = ( ! empty( $last ) ) ? '>' : '<'; + $query_args['graphql_after_cursor'] = $this->get_after_offset(); + $query_args['graphql_before_cursor'] = $this->get_before_offset(); + $query_args['graphql_cursor_compare'] = ! empty( $last ) ? '>' : '<'; /** * If the starting offset is not 0 sticky posts will not be queried as the automatic checks in wp-query don't * trigger due to the page parameter not being set in the query_vars, fixes #732 */ - if ( 0 !== $cursor_offset ) { + if ( empty( $query_args['graphql_after_cursor'] ) && empty( $query_args['graphql_before_cursor'] ) ) { $query_args['ignore_sticky_posts'] = true; } + /** * Pass the graphql $args to the WP_Query */ diff --git a/includes/data/connection/class-customer-connection-resolver.php b/includes/data/connection/class-customer-connection-resolver.php index fb80eb94..5b3d9ee8 100644 --- a/includes/data/connection/class-customer-connection-resolver.php +++ b/includes/data/connection/class-customer-connection-resolver.php @@ -61,12 +61,13 @@ public function get_query_args() { $query_args['number'] = $this->get_query_amount() + 1; /** - * Set the graphql_cursor_offset which is used by Config::graphql_wp_user_query_cursor_pagination_support - * to filter the WP_User_Query to support cursor pagination + * Set the cursor args. + * + * @see \WPGraphQL\Data\Config::graphql_wp_query_cursor_pagination_support */ - $cursor_offset = $this->get_offset(); - $query_args['graphql_cursor_offset'] = $cursor_offset; - $query_args['graphql_cursor_compare'] = ( ! empty( $last ) ) ? '>' : '<'; + $query_args['graphql_after_cursor'] = $this->get_after_offset(); + $query_args['graphql_before_cursor'] = $this->get_before_offset(); + $query_args['graphql_cursor_compare'] = ! empty( $last ) ? '>' : '<'; $input_fields = []; if ( ! empty( $this->args['where'] ) ) { diff --git a/includes/data/connection/class-order-item-connection-resolver.php b/includes/data/connection/class-order-item-connection-resolver.php index b4937fb1..5f274f7f 100644 --- a/includes/data/connection/class-order-item-connection-resolver.php +++ b/includes/data/connection/class-order-item-connection-resolver.php @@ -112,7 +112,7 @@ public function get_query() { } } - $cursor = absint( $this->get_offset() ); + $cursor = (int) $this->get_offset_for_cursor( $this->args['after'] ?? ( $this->args['before'] ?? 0 ) ); $first = ! empty( $this->args['first'] ) ? $this->args['first'] : null; $last = ! empty( $this->args['last'] ) ? $this->args['last'] : null; @@ -171,35 +171,4 @@ public function get_ids() { public function is_valid_offset( $offset ) { return 'string' === gettype( $offset ); } - - /** - * Get_offset - * - * This returns the offset to be used in the $query_args based on the $args passed to the - * GraphQL query. - * - * @return int|mixed - */ - public function get_offset() { - /** - * Defaults - */ - $offset = 0; - - /** - * Get the $after offset - */ - if ( ! empty( $this->args['after'] ) ) { - // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode - $offset = substr( base64_decode( $this->args['after'] ), strlen( 'arrayconnection:' ) ); - } elseif ( ! empty( $this->args['before'] ) ) { - // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode - $offset = substr( base64_decode( $this->args['before'] ), strlen( 'arrayconnection:' ) ); - } - - /** - * Return the higher of the two values - */ - return $offset; - } } diff --git a/includes/data/connection/class-product-connection-resolver.php b/includes/data/connection/class-product-connection-resolver.php index 6054f257..06ef6d11 100644 --- a/includes/data/connection/class-product-connection-resolver.php +++ b/includes/data/connection/class-product-connection-resolver.php @@ -146,12 +146,13 @@ public function get_query_args() { } /** - * Set the graphql_cursor_offset which is used by Config::graphql_wp_query_cursor_pagination_support - * to filter the WP_Query to support cursor pagination + * Set the cursor args. + * + * @see \WPGraphQL\Data\Config::graphql_wp_query_cursor_pagination_support */ - $cursor_offset = $this->get_offset(); - $query_args['graphql_cursor_offset'] = $cursor_offset; - $query_args['graphql_cursor_compare'] = ( ! empty( $last ) ) ? '>' : '<'; + $query_args['graphql_after_cursor'] = $this->get_after_offset(); + $query_args['graphql_before_cursor'] = $this->get_before_offset(); + $query_args['graphql_cursor_compare'] = ! empty( $last ) ? '>' : '<'; /** * Pass the graphql $args to the WP_Query diff --git a/includes/data/connection/class-shipping-method-connection-resolver.php b/includes/data/connection/class-shipping-method-connection-resolver.php index a0b2881e..c71779d5 100644 --- a/includes/data/connection/class-shipping-method-connection-resolver.php +++ b/includes/data/connection/class-shipping-method-connection-resolver.php @@ -84,35 +84,4 @@ public function get_ids() { public function is_valid_offset( $offset ) { return is_string( $offset ); } - - /** - * Get_offset - * - * This returns the offset to be used in the $query_args based on the $args passed to the - * GraphQL query. - * - * @return int|mixed - */ - public function get_offset() { - /** - * Defaults - */ - $offset = 0; - - /** - * Get the $after offset - */ - if ( ! empty( $this->args['after'] ) ) { - // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode - $offset = substr( base64_decode( $this->args['after'] ), strlen( 'arrayconnection:' ) ); - } elseif ( ! empty( $this->args['before'] ) ) { - // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode - $offset = substr( base64_decode( $this->args['before'] ), strlen( 'arrayconnection:' ) ); - } - - /** - * Return the higher of the two values - */ - return $offset; - } } diff --git a/includes/data/connection/class-tax-rate-connection-resolver.php b/includes/data/connection/class-tax-rate-connection-resolver.php index 789688b0..3bab10c7 100644 --- a/includes/data/connection/class-tax-rate-connection-resolver.php +++ b/includes/data/connection/class-tax-rate-connection-resolver.php @@ -68,12 +68,13 @@ public function get_query_args() { $query_args['items_per_page'] = min( max( absint( $first ), absint( $last ), 10 ), $this->query_amount ) + 1; /** - * Set the graphql_cursor_offset which is used by Config::graphql_wp_query_cursor_pagination_support - * to filter the WP_Query to support cursor pagination + * Set the cursor args. + * + * @see \WPGraphQL\Data\Config::graphql_wp_query_cursor_pagination_support */ - $cursor_offset = $this->get_offset(); - $query_args['graphql_cursor_offset'] = $cursor_offset; - $query_args['graphql_cursor_compare'] = ( ! empty( $last ) ) ? '>' : '<'; + $query_args['graphql_after_cursor'] = $this->get_after_offset(); + $query_args['graphql_before_cursor'] = $this->get_before_offset(); + $query_args['graphql_cursor_compare'] = ! empty( $last ) ? '>' : '<'; /** * If there's no orderby params in the inputArgs, set order based on the first/last argument