• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

AxeWP / wp-graphql-rank-math / 14810605469

03 May 2025 11:53AM UTC coverage: 88.44% (-0.5%) from 88.927%
14810605469

push

github

web-flow
fix: interface conflicts with WooGraphQL v0.21.1+ (#120)

* Fix WooGraphQL Product Type Expectations

* chore: phpcbf

* dev: add b/c with WooGraphQL < 0.21.1

* fix: add `ProductVariation` to woo product types

* chore: update changelog

* ci: bump woographql testing version

---------

Co-authored-by: Rob Belfort <rob.belfort@protonmail.com>

0 of 16 new or added lines in 1 file covered. (0.0%)

2586 of 2924 relevant lines covered (88.44%)

11.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php
1
<?php
2
/**
3
 * Registers the SEO objects for WPGraphQL for WooCommerce.
4
 *
5
 * @package WPGraphQL\RankMath\Extensions\WPGraphQLWooCommerce\Type\WPObject
6
 * @since 0.3.1
7
 */
8

9
declare( strict_types = 1 );
10

11
namespace WPGraphQL\RankMath\Extensions\WPGraphQLWooCommerce\Type\WPObject;
12

13
use WPGraphQL\RankMath\Type\WPInterface\ContentNodeSeo;
14
use WPGraphQL\RankMath\Utils\Utils;
15
use WPGraphQL\RankMath\Vendor\AxeWP\GraphQL\Interfaces\Registrable;
16
use WPGraphQL\RankMath\Vendor\AxeWP\GraphQL\Traits\TypeNameTrait;
17
use WPGraphQL\WooCommerce\WP_GraphQL_WooCommerce;
18

19
/**
20
 * Class - SeoObjects
21
 */
22
class SeoObjects implements Registrable {
23
        use TypeNameTrait;
24

25
        /**
26
         * {@inheritDoc}
27
         */
28
        public static function init(): void {
29
                add_action( 'graphql_register_types', [ static::class, 'register' ] );
×
30
        }
31

32
        /**
33
         * Registers the SEO GraphQL objects to the schema.
34
         */
35
        public static function register(): void {
36
                // Set SEO field types for product children.
37
                $product_types = WP_GraphQL_WooCommerce::get_enabled_product_types();
×
38
                /**
39
                 * @todo: remove this when we don't need to support WooGraphQL< 0.21.1
40
                 * @see https://github.com/AxeWP/wp-graphql-rank-math/pull/115#issuecomment-2660900767
41
                 */
NEW
42
                if ( defined( 'WPGRAPHQL_WOOCOMMERCE_VERSION' ) && version_compare( WPGRAPHQL_WOOCOMMERCE_VERSION, '0.21.1', '>=' ) ) {
×
NEW
43
                        $product_types = array_merge(
×
NEW
44
                                $product_types,
×
NEW
45
                                [
×
NEW
46
                                        'DownloadableProduct',
×
NEW
47
                                        'InventoriedProduct',
×
NEW
48
                                        'ProductUnion',
×
NEW
49
                                        'ProductWithAttributes',
×
NEW
50
                                        'ProductWithDimensions',
×
NEW
51
                                        'ProductWithPricing',
×
NEW
52
                                        'ProductWithVariations',
×
NEW
53
                                        'ProductVariation',
×
NEW
54
                                ]
×
NEW
55
                        );
×
56
                }
57

58
                foreach ( $product_types as $graphql_type_name ) {
×
59
                        Utils::overload_graphql_field_type( $graphql_type_name, 'seo', 'RankMathProductObjectSeo' );
×
60
                }
61

62
                /**
63
                 * @todo: remove this when we don't need to support WooGraphQL< 0.21.1
64
                 * @see https://github.com/AxeWP/wp-graphql-rank-math/pull/115#issuecomment-2660900767
65
                 */
NEW
66
                if ( defined( 'WPGRAPHQL_WOOCOMMERCE_VERSION' ) && version_compare( WPGRAPHQL_WOOCOMMERCE_VERSION, '0.21.1', '<' ) ) {
×
NEW
67
                        self::register_product_variation_types();
×
68
                }
69
        }
70

71
        /**
72
         * Registers the SEO types for product variations.
73
         *
74
         * @todo: remove this when we don't need to support WooGraphQL< 0.21.1
75
         * @see https://github.com/AxeWP/wp-graphql-rank-math/pull/115#issuecomment-2660900767
76
         */
77
        private static function register_product_variation_types(): void {
78
                // Register the Product Variation SEO type and apply it to the Product Variation and children.
79
                $type_name_for_product_variation = 'RankMathProductVariationObjectSeo';
×
80

81
                register_graphql_object_type(
×
82
                        $type_name_for_product_variation,
×
83
                        [
×
84
                                'description'     => __( 'The product variation object SEO data', 'wp-graphql-rank-math' ),
×
85
                                'interfaces'      => [ ContentNodeSeo::get_type_name() ],
×
86
                                'fields'          => [],
×
87
                                'eagerlyLoadType' => true,
×
88
                        ]
×
89
                );
×
90

91
                $product_variations = array_merge(
×
92
                        [
×
93
                                'ProductVariation',
×
94
                        ],
×
95
                        WP_GraphQL_WooCommerce::get_enabled_product_variation_types(),
×
96
                );
×
97

98
                foreach ( $product_variations as $product_variation ) {
×
99
                        Utils::overload_graphql_field_type( $product_variation, 'seo', $type_name_for_product_variation );
×
100
                }
101
        }
102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc