Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions includes/data/connection/class-coupon-connection-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
11 changes: 6 additions & 5 deletions includes/data/connection/class-customer-connection-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}
11 changes: 6 additions & 5 deletions includes/data/connection/class-product-connection-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
11 changes: 6 additions & 5 deletions includes/data/connection/class-tax-rate-connection-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down