From cb77fd608214562ff34d053265085995fb0383c8 Mon Sep 17 00:00:00 2001 From: Rob Belfort Date: Mon, 27 Jan 2025 07:44:12 -0500 Subject: [PATCH 1/6] Fix WooGraphQL Product Type Expectations --- .../Type/WPObject/SeoObjects.php | 36 +++++++------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php b/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php index 30d3643..c32aea3 100644 --- a/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php +++ b/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php @@ -34,34 +34,22 @@ public static function init(): void { */ public static function register(): void { // Set SEO field types for product children. - $product_types = WP_GraphQL_WooCommerce::get_enabled_product_types(); - - foreach ( $product_types as $graphql_type_name ) { - Utils::overload_graphql_field_type( $graphql_type_name, 'seo', 'RankMathProductObjectSeo' ); - } - - // Register the Product Variation SEO type and apply it to the Product Variation and children. - $type_name_for_product_variation = 'RankMathProductVariationObjectSeo'; - - register_graphql_object_type( - $type_name_for_product_variation, + $product_types = array_merge( + WP_GraphQL_WooCommerce::get_enabled_product_types(), [ - 'description' => __( 'The product variation object SEO data', 'wp-graphql-rank-math' ), - 'interfaces' => [ ContentNodeSeo::get_type_name() ], - 'fields' => [], - 'eagerlyLoadType' => true, + 'ProductUnion', + 'ProductWithPricing', + 'ProductWithDimensions', + 'InventoriedProduct', + 'DownloadableProduct', + 'ProductWithAttributes', + 'ProductWithVariations', ] ); - $product_variations = array_merge( - [ - 'ProductVariation', - ], - WP_GraphQL_WooCommerce::get_enabled_product_variation_types(), - ); - - foreach ( $product_variations as $product_variation ) { - Utils::overload_graphql_field_type( $product_variation, 'seo', $type_name_for_product_variation ); + foreach ( $product_types as $graphql_type_name ) { + Utils::overload_graphql_field_type( $graphql_type_name, 'seo', 'RankMathProductObjectSeo' ); } + } } From 0db7237b2fff5099d462a0cfd86cd4194b9c1187 Mon Sep 17 00:00:00 2001 From: Dovid Levine Date: Sat, 15 Feb 2025 13:02:03 +0200 Subject: [PATCH 2/6] chore: phpcbf --- .../WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php b/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php index c32aea3..fb18de7 100644 --- a/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php +++ b/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php @@ -10,7 +10,6 @@ namespace WPGraphQL\RankMath\Extensions\WPGraphQLWooCommerce\Type\WPObject; -use WPGraphQL\RankMath\Type\WPInterface\ContentNodeSeo; use WPGraphQL\RankMath\Utils\Utils; use WPGraphQL\RankMath\Vendor\AxeWP\GraphQL\Interfaces\Registrable; use WPGraphQL\RankMath\Vendor\AxeWP\GraphQL\Traits\TypeNameTrait; @@ -50,6 +49,5 @@ public static function register(): void { foreach ( $product_types as $graphql_type_name ) { Utils::overload_graphql_field_type( $graphql_type_name, 'seo', 'RankMathProductObjectSeo' ); } - } } From b23ac1bc86c150a43be66c0efb61c4ccffac02a9 Mon Sep 17 00:00:00 2001 From: Dovid Levine Date: Sat, 3 May 2025 12:39:32 +0300 Subject: [PATCH 3/6] dev: add b/c with WooGraphQL < 0.21.1 --- .../Type/WPObject/SeoObjects.php | 70 ++++++++++++++++--- 1 file changed, 59 insertions(+), 11 deletions(-) diff --git a/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php b/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php index fb18de7..2452c14 100644 --- a/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php +++ b/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php @@ -10,6 +10,7 @@ namespace WPGraphQL\RankMath\Extensions\WPGraphQLWooCommerce\Type\WPObject; +use WPGraphQL\RankMath\Type\WPInterface\ContentNodeSeo; use WPGraphQL\RankMath\Utils\Utils; use WPGraphQL\RankMath\Vendor\AxeWP\GraphQL\Interfaces\Registrable; use WPGraphQL\RankMath\Vendor\AxeWP\GraphQL\Traits\TypeNameTrait; @@ -33,21 +34,68 @@ public static function init(): void { */ public static function register(): void { // Set SEO field types for product children. - $product_types = array_merge( - WP_GraphQL_WooCommerce::get_enabled_product_types(), + $product_types = WP_GraphQL_WooCommerce::get_enabled_product_types(); + /** + * @todo: remove this when we don't need to support WooGraphQL< 0.21.1 + * @see https://github.com/AxeWP/wp-graphql-rank-math/pull/115#issuecomment-2660900767 + */ + if ( defined( 'WPGRAPHQL_WOOCOMMERCE_VERSION' ) && version_compare( WPGRAPHQL_WOOCOMMERCE_VERSION, '0.21.1', '>=' ) ) { + $product_types = array_merge( + $product_types, + [ + 'ProductUnion', + 'ProductWithPricing', + 'ProductWithDimensions', + 'InventoriedProduct', + 'DownloadableProduct', + 'ProductWithAttributes', + 'ProductWithVariations', + ] + ); + } + + foreach ( $product_types as $graphql_type_name ) { + Utils::overload_graphql_field_type( $graphql_type_name, 'seo', 'RankMathProductObjectSeo' ); + } + + /** + * @todo: remove this when we don't need to support WooGraphQL< 0.21.1 + * @see https://github.com/AxeWP/wp-graphql-rank-math/pull/115#issuecomment-2660900767 + */ + if ( defined( 'WPGRAPHQL_WOOCOMMERCE_VERSION' ) && version_compare( WPGRAPHQL_WOOCOMMERCE_VERSION, '0.21.1', '<' ) ) { + self::register_product_variation_types(); + } + } + + /** + * Registers the SEO types for product variations. + * + * @todo: remove this when we don't need to support WooGraphQL< 0.21.1 + * @see https://github.com/AxeWP/wp-graphql-rank-math/pull/115#issuecomment-2660900767 + */ + private static function register_product_variation_types(): void { + // Register the Product Variation SEO type and apply it to the Product Variation and children. + $type_name_for_product_variation = 'RankMathProductVariationObjectSeo'; + + register_graphql_object_type( + $type_name_for_product_variation, [ - 'ProductUnion', - 'ProductWithPricing', - 'ProductWithDimensions', - 'InventoriedProduct', - 'DownloadableProduct', - 'ProductWithAttributes', - 'ProductWithVariations', + 'description' => __( 'The product variation object SEO data', 'wp-graphql-rank-math' ), + 'interfaces' => [ ContentNodeSeo::get_type_name() ], + 'fields' => [], + 'eagerlyLoadType' => true, ] ); - foreach ( $product_types as $graphql_type_name ) { - Utils::overload_graphql_field_type( $graphql_type_name, 'seo', 'RankMathProductObjectSeo' ); + $product_variations = array_merge( + [ + 'ProductVariation', + ], + WP_GraphQL_WooCommerce::get_enabled_product_variation_types(), + ); + + foreach ( $product_variations as $product_variation ) { + Utils::overload_graphql_field_type( $product_variation, 'seo', $type_name_for_product_variation ); } } } From 974f0ed8c3e4446d40f094832329089c806d8f84 Mon Sep 17 00:00:00 2001 From: Dovid Levine Date: Sat, 3 May 2025 13:34:08 +0300 Subject: [PATCH 4/6] fix: add `ProductVariation` to woo product types --- .../WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php b/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php index 2452c14..4ea84be 100644 --- a/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php +++ b/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php @@ -43,13 +43,14 @@ public static function register(): void { $product_types = array_merge( $product_types, [ - 'ProductUnion', - 'ProductWithPricing', - 'ProductWithDimensions', - 'InventoriedProduct', 'DownloadableProduct', + 'InventoriedProduct', + 'ProductUnion', 'ProductWithAttributes', + 'ProductWithDimensions', + 'ProductWithPricing', 'ProductWithVariations', + 'ProductVariation', ] ); } From cf03cbd5c55d9847d87e267c8d0ffde3e26074f2 Mon Sep 17 00:00:00 2001 From: Dovid Levine Date: Sat, 3 May 2025 13:38:02 +0300 Subject: [PATCH 5/6] chore: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70b6cc0..7121eec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased] +- fix: Fix type conflicts on Product interfaces in WooGraphQL 0.21.1+. Props @robbiebel 🙌 - chore: bump PHPStan to v2.0.x - chore: Test compatibility with WordPress 6.8 and WPGraphQL 2.3. - chore: Update Composer dev-dependencies and lint. From 4943062c4efb869a2140f4c0d9f0ec5ef60d39be Mon Sep 17 00:00:00 2001 From: Dovid Levine Date: Sat, 3 May 2025 14:35:27 +0300 Subject: [PATCH 6/6] ci: bump woographql testing version --- bin/_lib.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bin/_lib.sh b/bin/_lib.sh index b8a0095..f222231 100644 --- a/bin/_lib.sh +++ b/bin/_lib.sh @@ -98,11 +98,19 @@ install_woographql() { echo "Installing WooCommerce..." if ! $(wp plugin is-installed woocommerce); then - wp plugin install woocommerce --activate + wp plugin install woocommerce --activate --allow-root fi if ! $(wp plugin is-installed wp-graphql-woocommerce); then - wp plugin install https://github.com/wp-graphql/wp-graphql-woocommerce/releases/download/v0.21.0/wp-graphql-woocommerce.zip --activate + wp plugin install https://github.com/wp-graphql/wp-graphql-woocommerce/archive/refs/heads/master.zip --allow-root + cd $WP_CORE_DIR/wp-content/plugins/wp-graphql-woocommerce + + if [ ! -d vendor ]; then + composer install --no-dev + fi + + wp plugin activate wp-graphql-woocommerce --allow-root + fi }