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

wp-graphql / wp-graphql-woocommerce / 23779262545

31 Mar 2026 03:37AM UTC coverage: 91.718% (+1.0%) from 90.757%
23779262545

push

github

web-flow
perf: Migrate type descriptions to lazy lambdas (#1005)

* perf: Migrate type descriptions to lazy lambdas

Convert all eager description strings from:
  'description' => __( '...', 'wp-graphql-woocommerce' ),
to deferred lambdas:
  'description' => static function () { return __( '...', 'wp-graphql-woocommerce' ); },

This defers the __() translation call until the description is actually
needed (e.g. during schema introspection), avoiding unnecessary
translation overhead on every GraphQL request. Mirrors the pattern
used in WPGraphQL core.

1206 descriptions converted across 169 files.

* chore: Linter compliances met

3598 of 3630 new or added lines in 167 files covered. (99.12%)

1 existing line in 1 file now uncovered.

18328 of 19983 relevant lines covered (91.72%)

145.82 hits per line

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

95.42
/includes/type/enum/class-id-type-enums.php
1
<?php
2
/**
3
 * Register *IdTypeEnum
4
 *
5
 * @package WPGraphQL\WooCommerce\Type\WPEnum
6
 * @since   0.0.1
7
 */
8

9
namespace WPGraphQL\WooCommerce\Type\WPEnum;
10

11
/**
12
 * Class - Id_Type_Enums
13
 */
14
class Id_Type_Enums {
15
        /**
16
         * Register the Enum used for setting the field to identify WC crud objects by
17
         *
18
         * @access public
19
         * @return void
20
         */
21
        public static function register() {
22
                register_graphql_enum_type(
285✔
23
                        'CouponIdTypeEnum',
285✔
24
                        [
285✔
25
                                'description' => static function () {
285✔
26
                                        return __( 'The Type of Identifier used to fetch a single Coupon. Default is ID.', 'wp-graphql-woocommerce' );
2✔
27
                                },
285✔
28
                                'values'      => [
285✔
29
                                        'id'          => self::get_value( 'id' ),
285✔
30
                                        'database_id' => self::get_value( 'database_id' ),
285✔
31
                                        'code'        => [
285✔
32
                                                'name'        => 'CODE',
285✔
33
                                                'value'       => 'code',
285✔
34
                                                'description' => static function () {
285✔
35
                                                        return __( 'Coupon code.', 'wp-graphql-woocommerce' );
135✔
36
                                                },
285✔
37
                                        ],
285✔
38
                                ],
285✔
39
                        ]
285✔
40
                );
285✔
41

42
                register_graphql_enum_type(
285✔
43
                        'OrderIdTypeEnum',
285✔
44
                        [
285✔
45
                                'description' => static function () {
285✔
46
                                        return __( 'The Type of Identifier used to fetch a single Order. Default is ID.', 'wp-graphql-woocommerce' );
2✔
47
                                },
285✔
48
                                'values'      => [
285✔
49
                                        'id'          => self::get_value( 'id' ),
285✔
50
                                        'database_id' => self::get_value( 'database_id' ),
285✔
51
                                        'order_key'   => [
285✔
52
                                                'name'        => 'ORDER_KEY',
285✔
53
                                                'value'       => 'order_key',
285✔
54
                                                'description' => static function () {
285✔
55
                                                        return __( 'Order key.', 'wp-graphql-woocommerce' );
141✔
56
                                                },
285✔
57
                                        ],
285✔
58
                                ],
285✔
59
                        ]
285✔
60
                );
285✔
61

62
                register_graphql_enum_type(
285✔
63
                        'ProductIdTypeEnum',
285✔
64
                        [
285✔
65
                                'description' => static function () {
285✔
66
                                        return __( 'The Type of Identifier used to fetch a single Product. Default is ID.', 'wp-graphql-woocommerce' );
2✔
67
                                },
285✔
68
                                'values'      => [
285✔
69
                                        'id'          => self::get_value( 'id' ),
285✔
70
                                        'database_id' => self::get_value( 'database_id' ),
285✔
71
                                        'slug'        => self::get_value( 'slug' ),
285✔
72
                                        'sku'         => [
285✔
73
                                                'name'        => 'SKU',
285✔
74
                                                'value'       => 'sku',
285✔
75
                                                'description' => static function () {
285✔
76
                                                        return __( 'Unique store identifier for product.', 'wp-graphql-woocommerce' );
132✔
77
                                                },
285✔
78
                                        ],
285✔
79
                                ],
285✔
80
                        ]
285✔
81
                );
285✔
82

83
                register_graphql_enum_type(
285✔
84
                        'ProductVariationIdTypeEnum',
285✔
85
                        [
285✔
86
                                'description' => static function () {
285✔
87
                                        return __( 'The Type of Identifier used to fetch a single ProductVariation. Default is ID.', 'wp-graphql-woocommerce' );
2✔
88
                                },
285✔
89
                                'values'      => [
285✔
90
                                        'id'          => self::get_value( 'id' ),
285✔
91
                                        'database_id' => self::get_value( 'database_id' ),
285✔
92
                                ],
285✔
93
                        ]
285✔
94
                );
285✔
95

96
                register_graphql_enum_type(
285✔
97
                        'RefundIdTypeEnum',
285✔
98
                        [
285✔
99
                                'description' => static function () {
285✔
100
                                        return __( 'The Type of Identifier used to fetch a single Refund. Default is ID.', 'wp-graphql-woocommerce' );
2✔
101
                                },
285✔
102
                                'values'      => [
285✔
103
                                        'id'          => self::get_value( 'id' ),
285✔
104
                                        'database_id' => self::get_value( 'database_id' ),
285✔
105
                                ],
285✔
106
                        ]
285✔
107
                );
285✔
108

109
                register_graphql_enum_type(
285✔
110
                        'ShippingMethodIdTypeEnum',
285✔
111
                        [
285✔
112
                                'description' => static function () {
285✔
113
                                        return __( 'The Type of Identifier used to fetch a single Shipping Method. Default is ID.', 'wp-graphql-woocommerce' );
2✔
114
                                },
285✔
115
                                'values'      => [
285✔
116
                                        'id'          => self::get_value( 'id' ),
285✔
117
                                        'database_id' => self::get_value( 'database_id' ),
285✔
118
                                ],
285✔
119
                        ]
285✔
120
                );
285✔
121

122
                register_graphql_enum_type(
285✔
123
                        'ShippingZoneIdTypeEnum',
285✔
124
                        [
285✔
125
                                'description' => static function () {
285✔
126
                                        return __( 'The Type of Identifier used to fetch a single Shipping Zone. Default is ID.', 'wp-graphql-woocommerce' );
2✔
127
                                },
285✔
128
                                'values'      => [
285✔
129
                                        'id'          => self::get_value( 'id' ),
285✔
130
                                        'database_id' => self::get_value( 'database_id' ),
285✔
131
                                ],
285✔
132
                        ]
285✔
133
                );
285✔
134

135
                register_graphql_enum_type(
285✔
136
                        'TaxRateIdTypeEnum',
285✔
137
                        [
285✔
138
                                'description' => static function () {
285✔
139
                                        return __( 'The Type of Identifier used to fetch a single Tax rate. Default is ID.', 'wp-graphql-woocommerce' );
2✔
140
                                },
285✔
141
                                'values'      => [
285✔
142
                                        'id'          => self::get_value( 'id' ),
285✔
143
                                        'database_id' => self::get_value( 'database_id' ),
285✔
144
                                ],
285✔
145
                        ]
285✔
146
                );
285✔
147
        }
148

149
        /**
150
         * Returns Enum Value definition.
151
         *
152
         * @param string $value  Enumeration value being retrieved.
153
         * @return array
154
         */
155
        private static function get_value( $value ) {
156
                switch ( $value ) {
157
                        case 'slug':
285✔
158
                                return [
285✔
159
                                        'name'        => 'SLUG',
285✔
160
                                        'value'       => 'slug',
285✔
161
                                        'description' => static function () {
285✔
162
                                                return __(
132✔
163
                                                        'Identify a resource by the slug. Available to non-hierarchcial Types where the slug is a unique identifier.',
132✔
164
                                                        'wp-graphql-woocommerce'
132✔
165
                                                );
132✔
166
                                        },
285✔
167
                                ];
285✔
168
                        case 'database_id':
285✔
169
                                return [
285✔
170
                                        'name'        => 'DATABASE_ID',
285✔
171
                                        'value'       => 'database_id',
285✔
172
                                        'description' => static function () {
285✔
173
                                                return __( 'Identify a resource by the Database ID.', 'wp-graphql-woocommerce' );
150✔
174
                                        },
285✔
175
                                ];
285✔
176
                        case 'uri':
285✔
177
                                return [
×
178
                                        'name'        => 'URI',
×
179
                                        'value'       => 'uri',
×
NEW
180
                                        'description' => static function () {
×
NEW
181
                                                return __( 'Identify a resource by the URI.', 'wp-graphql-woocommerce' );
×
NEW
182
                                        },
×
UNCOV
183
                                ];
×
184
                        case 'id':
285✔
185
                        default:
186
                                return [
285✔
187
                                        'name'        => 'ID',
285✔
188
                                        'value'       => 'global_id',
285✔
189
                                        'description' => static function () {
285✔
190
                                                return __( 'Identify a resource by the (hashed) Global ID.', 'wp-graphql-woocommerce' );
150✔
191
                                        },
285✔
192
                                ];
285✔
193
                }//end switch
194
        }
195
}
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