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

AxeWP / wp-graphql-rank-math / 15507442176

07 Jun 2025 11:36AM UTC coverage: 86.429% (-2.0%) from 88.44%
15507442176

Pull #121

github

web-flow
Merge c854da69f into 3bd3ede8c
Pull Request #121: dev: add support for lazy-loading `description`/`deprecationReason` config values

357 of 367 new or added lines in 66 files covered. (97.28%)

60 existing lines in 60 files now uncovered.

2541 of 2940 relevant lines covered (86.43%)

11.49 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\Helper\Compat;
16
use WPGraphQL\RankMath\Vendor\AxeWP\GraphQL\Interfaces\Registrable;
17
use WPGraphQL\RankMath\Vendor\AxeWP\GraphQL\Traits\TypeNameTrait;
18
use WPGraphQL\WooCommerce\WP_GraphQL_WooCommerce;
19

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

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

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

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

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

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

82
                register_graphql_object_type(
×
83
                        $type_name_for_product_variation,
×
84
                        // @todo Remove when WPGraphQL < 2.3.0 is dropped.
NEW
85
                        Compat::resolve_graphql_config(
×
NEW
86
                                [
×
NEW
87
                                        'description'     => static fn () => __( 'The product variation object SEO data', 'wp-graphql-rank-math' ),
×
NEW
88
                                        'interfaces'      => [ ContentNodeSeo::get_type_name() ],
×
NEW
89
                                        'fields'          => [],
×
NEW
90
                                        'eagerlyLoadType' => true,
×
NEW
91
                                ]
×
NEW
92
                        ),
×
UNCOV
93
                );
×
94

95
                $product_variations = array_merge(
×
96
                        [
×
97
                                'ProductVariation',
×
98
                        ],
×
99
                        WP_GraphQL_WooCommerce::get_enabled_product_variation_types(),
×
100
                );
×
101

102
                foreach ( $product_variations as $product_variation ) {
×
103
                        Utils::overload_graphql_field_type( $product_variation, 'seo', $type_name_for_product_variation );
×
104
                }
105
        }
106
}
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