From 56c245980efa0d2effeb083fb4b0e8aa68b4ecca Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Mon, 7 Mar 2022 09:54:48 -0700 Subject: [PATCH 1/8] #2274 - fix bug with the generalSettings.url field being removed from multisite installs in the 1.7 release --- src/Registry/TypeRegistry.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Registry/TypeRegistry.php b/src/Registry/TypeRegistry.php index 4181ad41e..05629f1d1 100644 --- a/src/Registry/TypeRegistry.php +++ b/src/Registry/TypeRegistry.php @@ -536,21 +536,21 @@ public function init_type_registry( TypeRegistry $type_registry ) { */ $allowed_setting_types = DataSource::get_allowed_settings_by_group( $this ); - if ( ! empty( $allowed_setting_types ) && is_array( $allowed_setting_types ) ) { + /** + * The url is not a registered setting for multisite, so this is a polyfill + * to expose the URL to the Schema for multisite sites + */ + if ( is_multisite() ) { + $this->register_field( 'GeneralSettings', 'url', [ + 'type' => 'String', + 'description' => __( 'Site URL.', 'wp-graphql' ), + 'resolve' => function () { + return get_site_url(); + }, + ] ); + } - /** - * The url is not a registered setting for multisite, so this is a polyfill - * to expose the URL to the Schema for multisite sites - */ - if ( is_multisite() ) { - register_graphql_field( 'GeneralSettings', 'url', [ - 'type' => 'String', - 'description' => __( 'Site URL.', 'wp-graphql' ), - 'resolve' => function () { - return get_site_url(); - }, - ] ); - } + if ( ! empty( $allowed_setting_types ) && is_array( $allowed_setting_types ) ) { foreach ( $allowed_setting_types as $group_name => $setting_type ) { From 7eb09bb83826a5446763d6cc0f51149e2881a765 Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Mon, 7 Mar 2022 10:25:17 -0700 Subject: [PATCH 2/8] - update settings fields to be keyed by field name instead of typename (fixes sorting in the UpdateSettings payload) - use register_graphql_object_type instead of $this->register_object_type for the SettingsGroup to ensure filters are applied on fields --- src/Mutation/UpdateSettings.php | 25 ++++++++++++------------- src/Type/ObjectType/SettingGroup.php | 8 +++----- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/Mutation/UpdateSettings.php b/src/Mutation/UpdateSettings.php index ece71cc40..cce6ba8f3 100644 --- a/src/Mutation/UpdateSettings.php +++ b/src/Mutation/UpdateSettings.php @@ -119,13 +119,24 @@ public static function get_output_fields( TypeRegistry $type_registry ) { */ $allowed_setting_groups = DataSource::get_allowed_settings_by_group( $type_registry ); + /** + * Get all of the settings, regardless of group + */ + $output_fields['allSettings'] = [ + 'type' => 'Settings', + 'description' => __( 'Update all settings.', 'wp-graphql' ), + 'resolve' => function () { + return true; + }, + ]; + if ( ! empty( $allowed_setting_groups ) && is_array( $allowed_setting_groups ) ) { foreach ( $allowed_setting_groups as $group => $setting_type ) { $setting_type = DataSource::format_group_name( $group ); $setting_type_name = Utils::format_type_name( $setting_type . 'Settings' ); - $output_fields[ $setting_type_name ] = [ + $output_fields[ Utils::format_field_name( $setting_type_name ) ] = [ 'type' => $setting_type_name, 'description' => sprintf( __( 'Update the %s setting.', 'wp-graphql' ), $setting_type_name ), 'resolve' => function () use ( $setting_type_name ) { @@ -135,18 +146,6 @@ public static function get_output_fields( TypeRegistry $type_registry ) { } } - - /** - * Get all of the settings, regardless of group - */ - $output_fields['allSettings'] = [ - 'type' => 'Settings', - 'description' => __( 'Update all settings.', 'wp-graphql' ), - 'resolve' => function () { - return true; - }, - ]; - return $output_fields; } diff --git a/src/Type/ObjectType/SettingGroup.php b/src/Type/ObjectType/SettingGroup.php index 4a7965171..9f6432d81 100644 --- a/src/Type/ObjectType/SettingGroup.php +++ b/src/Type/ObjectType/SettingGroup.php @@ -30,7 +30,7 @@ public static function register_settings_group( string $group_name, string $grou return null; } - $type_registry->register_object_type( + register_graphql_object_type( ucfirst( $group_name ) . 'Settings', [ 'description' => sprintf( __( 'The %s setting type', 'wp-graphql' ), $group_name ), @@ -95,10 +95,8 @@ public static function get_settings_group_fields( string $group_name, string $gr * Check to see if the user querying the email field has the 'manage_options' capability * All other options should be public by default */ - if ( 'admin_email' === $setting_field['key'] ) { - if ( ! current_user_can( 'manage_options' ) ) { - throw new UserError( __( 'Sorry, you do not have permission to view this setting.', 'wp-graphql' ) ); - } + if ( ( 'admin_email' === $setting_field['key'] ) && ! current_user_can( 'manage_options' ) ) { + throw new UserError( __( 'Sorry, you do not have permission to view this setting.', 'wp-graphql' ) ); } $option = ! empty( $setting_field['key'] ) ? get_option( $setting_field['key'] ) : null; From b94fccf4d98552a78f73765c6fa8651003cf924c Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Mon, 7 Mar 2022 10:27:58 -0700 Subject: [PATCH 3/8] - revert to use $type_registry->register_object_type --- src/Type/ObjectType/SettingGroup.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Type/ObjectType/SettingGroup.php b/src/Type/ObjectType/SettingGroup.php index 9f6432d81..4a7965171 100644 --- a/src/Type/ObjectType/SettingGroup.php +++ b/src/Type/ObjectType/SettingGroup.php @@ -30,7 +30,7 @@ public static function register_settings_group( string $group_name, string $grou return null; } - register_graphql_object_type( + $type_registry->register_object_type( ucfirst( $group_name ) . 'Settings', [ 'description' => sprintf( __( 'The %s setting type', 'wp-graphql' ), $group_name ), @@ -95,8 +95,10 @@ public static function get_settings_group_fields( string $group_name, string $gr * Check to see if the user querying the email field has the 'manage_options' capability * All other options should be public by default */ - if ( ( 'admin_email' === $setting_field['key'] ) && ! current_user_can( 'manage_options' ) ) { - throw new UserError( __( 'Sorry, you do not have permission to view this setting.', 'wp-graphql' ) ); + if ( 'admin_email' === $setting_field['key'] ) { + if ( ! current_user_can( 'manage_options' ) ) { + throw new UserError( __( 'Sorry, you do not have permission to view this setting.', 'wp-graphql' ) ); + } } $option = ! empty( $setting_field['key'] ) ? get_option( $setting_field['key'] ) : null; From 990a7a1bbb3c66a07027e5eed43d5024f73e36d0 Mon Sep 17 00:00:00 2001 From: Mark Kelnar <749603+markkelnar@users.noreply.github.com> Date: Mon, 7 Mar 2022 14:44:06 -0600 Subject: [PATCH 4/8] For repos that extend the docker testing image and dont have a package.json --- docker/testing.entrypoint.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docker/testing.entrypoint.sh b/docker/testing.entrypoint.sh index 770a21c01..2e4ade999 100644 --- a/docker/testing.entrypoint.sh +++ b/docker/testing.entrypoint.sh @@ -90,12 +90,16 @@ echo "Running composer install" COMPOSER_MEMORY_LIMIT=-1 composer install --no-interaction ## Install JavaScript Dependencies -echo "Running npm install" -npm ci +if [ -f package.json ]; then + echo "Running npm install" + npm ci -## Build the JavaScript app -echo "Building the JavaScript app" -npm build + ## Build the JavaScript app + echo "Building the JavaScript app" + npm build +else + echo "Skipping npm install" +fi # Install pcov/clobber if PHP7.1+ if version_gt $PHP_VERSION 7.0 && [[ -n "$COVERAGE" ]] && [[ -z "$USING_XDEBUG" ]]; then From 8488b36776fa87324b53d8bf0442a4ef94bbd693 Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Mon, 7 Mar 2022 14:32:59 -0700 Subject: [PATCH 5/8] - update .gitattributes to not ingore the packages directory - update composer.json to exclude the packages directory for plugin builds --- .gitattributes | 1 - composer.json | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitattributes b/.gitattributes index cc48bb985..fd596ea19 100644 --- a/.gitattributes +++ b/.gitattributes @@ -30,5 +30,4 @@ /phpstan.neon.dist export-ignore /schema.graphql export-ignore /node_modules export-ignore -/packages export-ignore /artifacts export-ignore diff --git a/composer.json b/composer.json index 3c11ad124..7c235c1b9 100644 --- a/composer.json +++ b/composer.json @@ -86,7 +86,10 @@ "fix-cs": [ "php ./vendor/bin/phpcbf" ], - "phpstan": ["phpstan analyze --ansi --memory-limit=1G"] + "phpstan": ["phpstan analyze --ansi --memory-limit=1G"], + "post-install-cmd": [ + "npm ci && npm run build" + ] }, "archive": { "exclude": [ @@ -98,7 +101,8 @@ "!.wordpress-org/", "docs/", "wp-graphql.zip", - "!build" + "!build", + "packages" ] } } From 2b51a7c18bc031c68310aa6b0dea1b0091bbcad3 Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Mon, 7 Mar 2022 14:59:12 -0700 Subject: [PATCH 6/8] - update changelog, versions for release --- CHANGELOG.md | 14 +++++++++++--- package.json | 2 +- readme.txt | 11 ++++++++++- src/WPGraphQL.php | 2 +- wp-graphql.php | 4 ++-- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a608c8258..2d5cef932 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,23 @@ # Changelog +## 1.7.2 + +### Chores / Bugfixes + +- ([#2276](https://github.com/wp-graphql/wp-graphql/pull/2276)): Fixes a bug where `generalSettings.url` field was not in the Schema for multisite installs. +- ([#2278](https://github.com/wp-graphql/wp-graphql/pull/2278)): Adds a composer post-install script that installs JS dependencies and builds the JS app when `composer install` is run +- ([#2277](https://github.com/wp-graphql/wp-graphql/pull/2277)): Adds a condition to the docker image to only run `npm` scripts if the project has a package.json. Thanks @markkelnar! + ## 1.7.1 -## Chores / Bugfixes +### Chores / Bugfixes - ([#2268](https://github.com/wp-graphql/wp-graphql/pull/2268)): Fixes a bug in GraphiQL that would update browser history with every change to a query param. ## 1.7.0 -## Chores / Bugfixes +### Chores / Bugfixes - ([#2228](https://github.com/wp-graphql/wp-graphql/pull/2228)): Allows optional fields to be set to empty values in the `updateUser` mutation. Thanks @victormattosvm! - ([#2247](https://github.com/wp-graphql/wp-graphql/pull/2247)): Add WordPress 5.9 to the automated testing matrix. Thanks @markkelnar! @@ -18,7 +26,7 @@ - ([#2263](https://github.com/wp-graphql/wp-graphql/pull/2263)): Adds documentation entry for WordPress Application Passwords guide. Thanks @abhisekmazumdar! - ([#2262](https://github.com/wp-graphql/wp-graphql/pull/2262)): Fixes a bug where settings registered via the core `register_setting()` API would cause Schema Introspection failures, causing GraphiQL and other tools to not work properly. -## New Features +### New Features - ([#2248](https://github.com/wp-graphql/wp-graphql/pull/2248)): WPGraphiQL (the GraphiQL IDE in the WordPress dashboard) has been re-built to have an extension architecture and some updated user interfaces. Thanks for contributing to this effort @scottyzen! - ([#2246](https://github.com/wp-graphql/wp-graphql/pull/2246)): Adds support for querying the `avatar` for the CommentAuthor Type and the Commenter Interface type. diff --git a/package.json b/package.json index 6fa7a9ec0..1b41871a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wp-graphql", - "version": "1.7.1", + "version": "1.7.2", "description": "GraphQL API for WordPress", "homepage": "https://github.com/wp-graphql/wp-graphql#readme", "author": "WPGraphQL (https://www.wpgraphql.com)", diff --git a/readme.txt b/readme.txt index af7f3d3bf..4c8cfd787 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: GraphQL, API, Gatsby, Headless, Decoupled, React, Nextjs, Vue, Apollo, RES Requires at least: 5.0 Tested up to: 5.9.1 Requires PHP: 7.1 -Stable tag: 1.7.1 +Stable tag: 1.7.2 License: GPL-3 License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -131,6 +131,15 @@ Composer dependencies are no longer versioned in Github. Recommended install sou == Changelog == += 1.7.2 = + +**Chores / Bugfixes** + +- ([#2276](https://github.com/wp-graphql/wp-graphql/pull/2276)): Fixes a bug where `generalSettings.url` field was not in the Schema for multisite installs. +- ([#2278](https://github.com/wp-graphql/wp-graphql/pull/2278)): Adds a composer post-install script that installs JS dependencies and builds the JS app when `composer install` is run +- ([#2277](https://github.com/wp-graphql/wp-graphql/pull/2277)): Adds a condition to the docker image to only run `npm` scripts if the project has a package.json. Thanks @markkelnar! + + = 1.7.1 = **Chores / Bugfixes** diff --git a/src/WPGraphQL.php b/src/WPGraphQL.php index 4c0b12e4d..47b3f07e2 100644 --- a/src/WPGraphQL.php +++ b/src/WPGraphQL.php @@ -130,7 +130,7 @@ private function setup_constants() { // Plugin version. if ( ! defined( 'WPGRAPHQL_VERSION' ) ) { - define( 'WPGRAPHQL_VERSION', '1.7.1' ); + define( 'WPGRAPHQL_VERSION', '1.7.2' ); } // Plugin Folder Path. diff --git a/wp-graphql.php b/wp-graphql.php index 30ce457a1..f4e9a1b98 100644 --- a/wp-graphql.php +++ b/wp-graphql.php @@ -6,7 +6,7 @@ * Description: GraphQL API for WordPress * Author: WPGraphQL * Author URI: http://www.wpgraphql.com - * Version: 1.7.1 + * Version: 1.7.2 * Text Domain: wp-graphql * Domain Path: /languages/ * Requires at least: 5.0 @@ -18,7 +18,7 @@ * @package WPGraphQL * @category Core * @author WPGraphQL - * @version 1.7.1 + * @version 1.7.2 */ // Exit if accessed directly. From 78e4e63ac34800b27f56b0b6c5f500b8a9465d0b Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Mon, 7 Mar 2022 15:09:34 -0700 Subject: [PATCH 7/8] - remove redundant calls to install & build npm packages (composer install now does this via post-install-cmd) --- .github/workflows/deploy-to-wordpress.yml | 7 +------ .github/workflows/graphiql-e2e-tests.yml | 4 +--- .github/workflows/graphiql-unit-tests.yml | 3 --- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/.github/workflows/deploy-to-wordpress.yml b/.github/workflows/deploy-to-wordpress.yml index eff034238..804dbfa8b 100644 --- a/.github/workflows/deploy-to-wordpress.yml +++ b/.github/workflows/deploy-to-wordpress.yml @@ -18,12 +18,7 @@ jobs: - name: Install PHP dependencies run: | composer install --no-dev --optimize-autoloader - - name: Install NPM Dependencies - run: | - npm install - - name: Build JavaScript App (GraphiQL) - run: | - npm run build + - name: WordPress Plugin Deploy uses: 10up/action-wordpress-plugin-deploy@stable env: diff --git a/.github/workflows/graphiql-e2e-tests.yml b/.github/workflows/graphiql-e2e-tests.yml index 5fa072a21..f3e60a7ca 100644 --- a/.github/workflows/graphiql-e2e-tests.yml +++ b/.github/workflows/graphiql-e2e-tests.yml @@ -38,9 +38,7 @@ jobs: - name: Install Composer Dependencies run: | composer install --no-dev - - name: Npm install and build - run: | - npm ci && npm run build + - name: Install WordPress run: | npm run wp-env start diff --git a/.github/workflows/graphiql-unit-tests.yml b/.github/workflows/graphiql-unit-tests.yml index 466915e7c..5f0467836 100644 --- a/.github/workflows/graphiql-unit-tests.yml +++ b/.github/workflows/graphiql-unit-tests.yml @@ -39,9 +39,6 @@ jobs: run: | composer install --no-dev - - name: Npm install and build - run: | - npm install && npm run build - name: Install WordPress run: | npm run wp-env start From 8fcb6dbb59807c6a917bf2e3217489df43c3c301 Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Tue, 8 Mar 2022 09:03:01 -0700 Subject: [PATCH 8/8] - remove code from docker/testing.entrypoint.sh that install npm dependencies. The npm install is now triggered as the post-install-cmd in composer.json --- docker/app.post-setup.sh | 2 ++ docker/testing.entrypoint.sh | 14 ++------------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/docker/app.post-setup.sh b/docker/app.post-setup.sh index f577bd841..442f5313c 100644 --- a/docker/app.post-setup.sh +++ b/docker/app.post-setup.sh @@ -13,3 +13,5 @@ if $( wp maintenance-mode is-active --allow-root ); then echo "Deactivating maintenance mode" wp maintenance-mode deactivate --allow-root fi + + diff --git a/docker/testing.entrypoint.sh b/docker/testing.entrypoint.sh index 2e4ade999..624db42d2 100644 --- a/docker/testing.entrypoint.sh +++ b/docker/testing.entrypoint.sh @@ -83,23 +83,13 @@ if [ ! -f "$PROJECT_DIR/c3.php" ]; then curl -L 'https://raw.github.com/Codeception/c3/2.0/c3.php' > "$PROJECT_DIR/c3.php" fi -# Install PHP dependencies + +# Install the PHP dependencies echo "Running composer update" COMPOSER_MEMORY_LIMIT=-1 composer update echo "Running composer install" COMPOSER_MEMORY_LIMIT=-1 composer install --no-interaction -## Install JavaScript Dependencies -if [ -f package.json ]; then - echo "Running npm install" - npm ci - - ## Build the JavaScript app - echo "Building the JavaScript app" - npm build -else - echo "Skipping npm install" -fi # Install pcov/clobber if PHP7.1+ if version_gt $PHP_VERSION 7.0 && [[ -n "$COVERAGE" ]] && [[ -z "$USING_XDEBUG" ]]; then