Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [WIP] unstable term cursor identical names #2930

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
# Changelog

## 1.17.0

### New Features

- [#2940](https://github.com/wp-graphql/wp-graphql/pull/2940): feat: add graphql_format_name() access method
- [#2256](https://github.com/wp-graphql/wp-graphql/pull/2256): feat: add connectedTerms connection to Taxonomy Object

### Chores / Bugfixes

- [#2808](https://github.com/wp-graphql/wp-graphql/pull/2808): fix: fallback to template filename if sanitized name is empty
- [#2968](https://github.com/wp-graphql/wp-graphql/pull/2968): fix: Add graphql_debug warning when using `hasPublishedPosts: ATTACHMENT`
- [#2968](https://github.com/wp-graphql/wp-graphql/pull/2968): fix: improve DX for updateComment mutation
- [#2962](https://github.com/wp-graphql/wp-graphql/pull/2962): fix: respect hasPublishedPosts where arg on unauthenticated users queries
- [#2967](https://github.com/wp-graphql/wp-graphql/pull/2967): fix: use all roles for UserRoleEnum instead of the filtered editible_roles
- [#2940](https://github.com/wp-graphql/wp-graphql/pull/2940): fix: Decode slug so it works with other languages
- [#2959](https://github.com/wp-graphql/wp-graphql/pull/2959): chore: remove @phpstan-ignore annotations
- [#2945](https://github.com/wp-graphql/wp-graphql/pull/2945): fix: rename fields registered by connections when using `rename_graphql_field()`
- [#2949](https://github.com/wp-graphql/wp-graphql/pull/2949): fix: correctly get default user role for settings selectbox
- [#2955](https://github.com/wp-graphql/wp-graphql/pull/2955): test: back-fill register_graphql_input|union_type() tests
- [#2953](https://github.com/wp-graphql/wp-graphql/pull/2953): fix: term uri, early return. (Follow up to [#2341](https://github.com/wp-graphql/wp-graphql/pull/2341))
- [#2956](https://github.com/wp-graphql/wp-graphql/pull/2956): chore(deps-dev): bump postcss from 8.4.12 to 8.4.31
- [#2954](https://github.com/wp-graphql/wp-graphql/pull/2954): fix: regression to autoloader for bedrock sites. (Follow-up to [#2935](https://github.com/wp-graphql/wp-graphql/pull/2935))
- [#2950](https://github.com/wp-graphql/wp-graphql/pull/2950): fix: rename typo in component name - AuthSwitchProvider
- [#2948](https://github.com/wp-graphql/wp-graphql/pull/2948): chore: fix spelling mistakes (non-logical)
- [#2944](https://github.com/wp-graphql/wp-graphql/pull/2944): fix: skip setting if no $setting['group']
- [#2934](https://github.com/wp-graphql/wp-graphql/pull/2934): chore(deps-dev): bump composer/composer from 2.2.21 to 2.2.22
- [#2936](https://github.com/wp-graphql/wp-graphql/pull/2936): chore(deps): bump graphql from 16.5.0 to 16.8.1
- [#2341](https://github.com/wp-graphql/wp-graphql/pull/2341): fix: wrong term URI on sub-sites of multisite subdomain installs
- [#2935](https://github.com/wp-graphql/wp-graphql/pull/2935): fix: admin notice wasn't displaying if composer dependencies were missing
- [#2933](https://github.com/wp-graphql/wp-graphql/pull/2933): chore: remove unused parameters from resolver callbacks
- [#2932](https://github.com/wp-graphql/wp-graphql/pull/2932): chore: cleanup PHPCS inline annotations
- [#2934](https://github.com/wp-graphql/wp-graphql/pull/2634): chore: use .php extension for stub files
- [#2924](https://github.com/wp-graphql/wp-graphql/pull/2924): chore: upgrade WPCS to v3.0
- [#2921](https://github.com/wp-graphql/wp-graphql/pull/2921): fix: zip artifact in GitHub not in sub folder

## 1.16.0

### Upgrade Notice
Expand Down
2 changes: 1 addition & 1 deletion access-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @param string $replacement The replacement character for invalid characters. Defaults to '_'.
* @param string $regex The regex to use to match invalid characters. Defaults to '/[^A-Za-z0-9_]/i'.
*
* @since @todo
* @since v1.17.0
*/
function graphql_format_name( string $name, string $replacement = '_', string $regex = '/[^A-Za-z0-9_]/i' ): string {
return Utils::format_graphql_name( $name, $replacement, $regex );
Expand Down
39 changes: 37 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: GraphQL, JSON, API, Gatsby, Faust, Headless, Decoupled, Svelte, React, Nex
Requires at least: 5.0
Tested up to: 6.2
Requires PHP: 7.1
Stable tag: 1.16.0
Stable tag: 1.17.0
License: GPL-3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -252,9 +252,44 @@ Composer dependencies are no longer versioned in Github. Recommended install sou

== Changelog ==

= 1.17.0 =

**New Features**

- [#2940](https://github.com/wp-graphql/wp-graphql/pull/2940): feat: add graphql_format_name() access method
- [#2256](https://github.com/wp-graphql/wp-graphql/pull/2256): feat: add connectedTerms connection to Taxonomy Object

**Chores / Bugfixes**

- [#2808](https://github.com/wp-graphql/wp-graphql/pull/2808): fix: fallback to template filename if sanitized name is empty
- [#2968](https://github.com/wp-graphql/wp-graphql/pull/2968): fix: Add graphql_debug warning when using `hasPublishedPosts: ATTACHMENT`
- [#2968](https://github.com/wp-graphql/wp-graphql/pull/2968): fix: improve DX for updateComment mutation
- [#2962](https://github.com/wp-graphql/wp-graphql/pull/2962): fix: respect hasPublishedPosts where arg on unauthenticated users queries
- [#2967](https://github.com/wp-graphql/wp-graphql/pull/2967): fix: use all roles for UserRoleEnum instead of the filtered editible_roles
- [#2940](https://github.com/wp-graphql/wp-graphql/pull/2940): fix: Decode slug so it works with other languages
- [#2959](https://github.com/wp-graphql/wp-graphql/pull/2959): chore: remove @phpstan-ignore annotations
- [#2945](https://github.com/wp-graphql/wp-graphql/pull/2945): fix: rename fields registered by connections when using `rename_graphql_field()`
- [#2949](https://github.com/wp-graphql/wp-graphql/pull/2949): fix: correctly get default user role for settings selectbox
- [#2955](https://github.com/wp-graphql/wp-graphql/pull/2955): test: back-fill register_graphql_input|union_type() tests
- [#2953](https://github.com/wp-graphql/wp-graphql/pull/2953): fix: term uri, early return. (Follow up to [#2341](https://github.com/wp-graphql/wp-graphql/pull/2341))
- [#2956](https://github.com/wp-graphql/wp-graphql/pull/2956): chore(deps-dev): bump postcss from 8.4.12 to 8.4.31
- [#2954](https://github.com/wp-graphql/wp-graphql/pull/2954): fix: regression to autoloader for bedrock sites. (Follow-up to [#2935](https://github.com/wp-graphql/wp-graphql/pull/2935))
- [#2950](https://github.com/wp-graphql/wp-graphql/pull/2950): fix: rename typo in component name - AuthSwitchProvider
- [#2948](https://github.com/wp-graphql/wp-graphql/pull/2948): chore: fix spelling mistakes (non-logical)
- [#2944](https://github.com/wp-graphql/wp-graphql/pull/2944): fix: skip setting if no $setting['group']
- [#2934](https://github.com/wp-graphql/wp-graphql/pull/2934): chore(deps-dev): bump composer/composer from 2.2.21 to 2.2.22
- [#2936](https://github.com/wp-graphql/wp-graphql/pull/2936): chore(deps): bump graphql from 16.5.0 to 16.8.1
- [#2341](https://github.com/wp-graphql/wp-graphql/pull/2341): fix: wrong term URI on sub-sites of multisite subdomain installs
- [#2935](https://github.com/wp-graphql/wp-graphql/pull/2935): fix: admin notice wasn't displaying if composer dependencies were missing
- [#2933](https://github.com/wp-graphql/wp-graphql/pull/2933): chore: remove unused parameters from resolver callbacks
- [#2932](https://github.com/wp-graphql/wp-graphql/pull/2932): chore: cleanup PHPCS inline annotations
- [#2934](https://github.com/wp-graphql/wp-graphql/pull/2634): chore: use .php extension for stub files
- [#2924](https://github.com/wp-graphql/wp-graphql/pull/2924): chore: upgrade WPCS to v3.0
- [#2921](https://github.com/wp-graphql/wp-graphql/pull/2921): fix: zip artifact in GitHub not in sub folder

= 1.16.0 =

### New Features
**New Features**

- [#2918](https://github.com/wp-graphql/wp-graphql/pull/2918): feat: Use graphql endpoint without scheme in url header.
- [#2882](https://github.com/wp-graphql/wp-graphql/pull/2882): feat: Config and Cursor Classes refactor
Expand Down
11 changes: 11 additions & 0 deletions src/Data/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,17 @@ public function graphql_wp_term_query_cursor_pagination_support( array $pieces,
$pieces['where'] = $pieces['where'] . $before_cursor->get_where();
}

// Check the cursor compare order
$order = '>' === $args['graphql_cursor_compare'] ? 'ASC' : 'DESC';

// Get Cursor ID key.
$cursor = new TermObjectCursor( $args );
$key = $cursor->get_cursor_id_key();

// If there is a cursor compare in the arguments, use it as the stabilizer for cursors.
$pieces['orderby'] = "{$pieces['orderby']} {$pieces['order']}, {$key} {$order}";
$pieces['order'] = '';

return $pieces;
}

Expand Down
7 changes: 2 additions & 5 deletions src/Data/Cursor/TermObjectCursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,9 @@ public function get_where() {
}

/**
* If there's no cursor_compare fields applied then compare by the ID field.
* Stabilize cursor by consistently comparing with the ID.
*/
if ( ! $this->builder->has_fields() ) {
$this->compare_with_id_field();
}

$this->compare_with_id_field();

return $this->to_sql();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ public static function prepare_date_response( string $date_gmt, $date = null ) {
* Format a GraphQL name according to the GraphQL spec.
*
* Per the GraphQL spec, characters in names are limited to Latin ASCII letter, digits, or underscores.
*
*
* @see http://spec.graphql.org/draft/#sec-Names
*
* @param string $name The name to format.
* @param string $replacement The replacement character for invalid characters. Defaults to '_'.
* @param string $regex The regex to use to match invalid characters. Defaults to '/[^A-Za-z0-9_]/i'.
*
* @since @todo
* @since v1.17.0
*/
public static function format_graphql_name( string $name, string $replacement = '_', string $regex = '/[^A-Za-z0-9_]/i' ): string {
if ( empty( $name ) ) {
Expand Down
20 changes: 8 additions & 12 deletions tests/wpunit/PluginConnectionQueriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,30 +336,26 @@ public function testQueryWithFirstAndLast() {
public function testPluginsQueryWithWhereArgs() {
$query = $this->getQuery();

$active_plugin = 'WPGraphQL';
$active_plugin_name = 'WPGraphQL';
$active_plugin = 'wp-graphql/wp-graphql.php';
global $wp_version;

$inactive_plugin = 'Akismet Anti-Spam: Spam Protection';

// previous versions of WordPress have a different name of the plugin shipped with the docker images
if ( version_compare( $wp_version, '6.2', '<') ) {
$inactive_plugin = 'Akismet Anti-Spam';
}
$inactive_plugin = 'akismet/akismet.php';

wp_set_current_user( $this->admin );

// Filter by search term

$variables = [
'where' => [
'search' => $active_plugin,
'search' => $active_plugin_name,
],
];

$actual = $this->graphql( compact( 'query', 'variables' ) );
$this->assertIsValidQueryResponse( $actual );

$actual_plugins = array_column( $actual['data']['plugins']['nodes'], 'name' );
$actual_plugins = array_column( $actual['data']['plugins']['nodes'], 'path' );
$this->assertContains( $active_plugin, $actual_plugins );
$this->assertNotContains( $inactive_plugin, $actual_plugins );

Expand All @@ -375,7 +371,7 @@ public function testPluginsQueryWithWhereArgs() {

$this->assertIsValidQueryResponse( $actual );

$actual_plugins = array_column( $actual['data']['plugins']['nodes'], 'name' );
$actual_plugins = array_column( $actual['data']['plugins']['nodes'], 'path' );
$this->assertContains( $active_plugin, $actual_plugins );
$this->assertNotContains( $inactive_plugin, $actual_plugins );

Expand All @@ -385,7 +381,7 @@ public function testPluginsQueryWithWhereArgs() {
$actual = $this->graphql( compact( 'query', 'variables' ) );
$this->assertIsValidQueryResponse( $actual );

$actual_plugins = array_column( $actual['data']['plugins']['nodes'], 'name' );
$actual_plugins = array_column( $actual['data']['plugins']['nodes'], 'path' );
$this->assertContains( $inactive_plugin, $actual_plugins );
$this->assertNotContains( $active_plugin, $actual_plugins );

Expand All @@ -399,7 +395,7 @@ public function testPluginsQueryWithWhereArgs() {
$actual = $this->graphql( compact( 'query', 'variables' ) );
$this->assertIsValidQueryResponse( $actual );

$actual_plugins = array_column( $actual['data']['plugins']['nodes'], 'name' );
$actual_plugins = array_column( $actual['data']['plugins']['nodes'], 'path' );
$this->assertContains( $inactive_plugin, $actual_plugins );
$this->assertNotContains( $active_plugin, $actual_plugins );
}
Expand Down