Skip to content

Commit

Permalink
Merge pull request #95 from justlevine/chore/improved-connection-reso…
Browse files Browse the repository at this point in the history
…lvers

chore!: bump minimum WPGraphQL and use new Connection Resolver API
  • Loading branch information
justlevine authored May 11, 2024
2 parents 73b86d3 + 452cb67 commit 26c1233
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 35 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## [Unreleased]
- chore!: Bump minimum supported WPGraphQL version to v1.26.0.
- dev: Update `RedirectionConnectionResolver` for v1.26.0 compatibility.
- fix: Correctly resolve `rankMathSettings.homepage.description` field. Props @offminded 🙌
- chore: Update Composer dev-dependencies to latest versions and address uncovered lints.
- tests: Update compatibility with `[email protected]`.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Adds WPGraphQL support for [Rank Math SEO](https://rankmath.com/). Built with [W

* PHP 7.4 - 8.2+
* WordPress 6.0+
* WPGraphQL 1.14.0+
* WPGraphQL 1.26.0+
* RankMath SEO 1.0.201+

## Quick Install
Expand Down
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Tags: GraphQL, Gatsby, Headless, WPGraphQL, React, Rest, RankMath, Seo, Schema
Requires at least: 6.0
Tested up to: 6.5.0
Requires PHP: 7.4
Requires WPGraphQL: 1.14.0
Requires Plugins: wp-graphql, seo-by-rank-math
Requires WPGraphQL: 1.26.0
Stable tag: 0.2.0
License: GPL-3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,33 @@
class RedirectionConnectionResolver extends AbstractConnectionResolver {
/**
* {@inheritDoc}
*
* @var ?array<string,mixed>
*/
protected $query;

/**
* {@inheritDoc}
*/
public function get_loader_name() {
protected function loader_name(): string {
return RedirectionsLoader::$name;
}

/**
* {@inheritDoc}
*/
public function get_query_args() {
protected function prepare_query_args( array $args ): array {
/**
* Prepare for later use
*/
$last = ! empty( $this->args['last'] ) ? $this->args['last'] : null;
$first = ! empty( $this->args['first'] ) ? $this->args['first'] : null;
$last = ! empty( $args['last'] ) ? $args['last'] : null;

$query_args = [];

if ( ! empty( $this->args['where']['search'] ) ) {
$query_args['search'] = $this->args['where']['search'];
if ( ! empty( $args['where']['search'] ) ) {
$query_args['search'] = $args['where']['search'];
}

$query_args['status'] = ! empty( $this->args['where']['status'] ) ? $this->args['where']['status'] : 'active';
$query_args['status'] = ! empty( $args['where']['status'] ) ? $args['where']['status'] : 'active';

if ( ! empty( $this->args['where']['orderby']['field'] ) ) {
$query_args['orderby'] = $this->args['where']['orderby']['field'];
if ( ! empty( $args['where']['orderby']['field'] ) ) {
$query_args['orderby'] = $args['where']['orderby']['field'];
}

$query_args['order'] = ! empty( $this->args['where']['orderby']['order'] ) ? $this->args['where']['orderby']['order'] : 'DESC';
$query_args['order'] = ! empty( $args['where']['orderby']['order'] ) ? $args['where']['orderby']['order'] : 'DESC';

// If $last is set, we need to reverse the order.
if ( ! empty( $last ) ) {
Expand All @@ -66,18 +58,18 @@ public function get_query_args() {
/**
* Set limit the highest value of $first and $last, with a (filterable) max of 100
*/
$query_args['limit'] = $this->one_to_one ? 1 : min( max( absint( $first ), absint( $last ), 10 ), $this->query_amount ) + 1;
$query_args['limit'] = $this->one_to_one ? 1 : $this->get_query_amount() + 1;

/**
* Set the before and after cursors. This will modify the query in CoreSchemaFilters::add_redirection_pagination_support()
*/
$query_args['graphql_cursor_compare'] = ! empty( $last ) ? '>' : '<';

if ( ! empty( $this->args['after'] ) ) {
if ( ! empty( $args['after'] ) ) {
$query_args['graphql_after_cursor'] = $this->get_after_offset();
}

if ( ! empty( $this->args['before'] ) ) {
if ( ! empty( $args['before'] ) ) {
$query_args['graphql_before_cursor'] = $this->get_before_offset();
}

Expand All @@ -87,27 +79,27 @@ public function get_query_args() {
/**
* {@inheritDoc}
*/
public function get_query() {
if ( ! isset( $this->query ) ) {
$query = RMUtils::get_redirections( $this->query_args ?? [] );
protected function query( array $query_args ) {
$query = RMUtils::get_redirections( $query_args );

// Prime the cache for each of the queried redirections.
$loader = $this->getLoader();
// Prime the cache for each of the queried redirections.
$loader = $this->get_loader();
if ( isset( $query['redirections'] ) ) {
foreach ( $query['redirections'] as $redirection ) {
$loader->prime( $redirection['id'], $redirection );
}

$this->query = $query;
}

return $this->query;
return $query;
}

/**
* {@inheritDoc}
*/
public function should_execute() {
if ( isset( $this->query_args['status'] ) && 'active' === $this->query_args['status'] ) {
$query_args = $this->get_query_args();

if ( isset( $query_args['status'] ) && 'active' === $query_args['status'] ) {
return true;
}

Expand All @@ -126,7 +118,8 @@ public function is_valid_offset( $offset ) {
*/
public function get_ids_from_query() {
$ids = [];
$queried = $this->query['redirections'] ?? [];
$query = $this->get_query();
$queried = ! empty( $query['redirections'] ) ? $query['redirections'] : [];

if ( empty( $queried ) ) {
return $ids;
Expand All @@ -135,7 +128,8 @@ public function get_ids_from_query() {
$ids = array_column( $queried, 'id' );

// If we're going backwards, we need to reverse the array.
if ( ! empty( $this->args['last'] ) ) {
$args = $this->get_args();
if ( ! empty( $args['last'] ) ) {
$ids = array_reverse( $ids );
}

Expand Down
4 changes: 2 additions & 2 deletions wp-graphql-rank-math.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Tested up to: 6.5.0
* Requires PHP: 7.4
* Requires Plugins: wp-graphql, seo-by-rank-math
* WPGraphQL requires at least: 1.14.0
* WPGraphQL requires at least: 1.26.0
* License: GPL-3
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
*
Expand Down Expand Up @@ -96,7 +96,7 @@ function constants(): void {
* @return array<string, string> List of dependencies that are not ready.
*/
function dependencies_not_ready(): array {
$wpgraphql_version = '1.14.0';
$wpgraphql_version = '1.26.0';
$rankmath_version = '1.0.201';

$deps = [];
Expand Down

0 comments on commit 26c1233

Please sign in to comment.