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

wp-graphql / wp-graphql-woocommerce / 23675310087

28 Mar 2026 02:18AM UTC coverage: 89.672% (+0.2%) from 89.424%
23675310087

Pull #1003

github

web-flow
Merge fb368619b into 6fb7b226f
Pull Request #1003: devops: WC email template tests, COT cursor HPOS fix, checkout account auth

75 of 81 new or added lines in 5 files covered. (92.59%)

46 existing lines in 8 files now uncovered.

15915 of 17748 relevant lines covered (89.67%)

143.3 hits per line

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

95.6
/includes/type/object/class-meta-data-type.php
1
<?php
2
/**
3
 * WPObject Type - Order_Item_Type
4
 *
5
 * Registers MetaData type and queries
6
 *
7
 * @package WPGraphQL\WooCommerce\Type\WPObject
8
 * @since   0.0.2
9
 */
10

11
namespace WPGraphQL\WooCommerce\Type\WPObject;
12

13
/**
14
 * Class Meta_Data_Type
15
 */
16
class Meta_Data_Type {
17
        /**
18
         * Register Order type and queries to the WPGraphQL schema
19
         *
20
         * @return void
21
         */
22
        public static function register() {
23
                register_graphql_object_type(
283✔
24
                        'MetaData',
283✔
25
                        [
283✔
26
                                'description' => __( 'Extra data defined on the WC object', 'wp-graphql-woocommerce' ),
283✔
27
                                'fields'      => [
283✔
28
                                        'id'    => [
283✔
29
                                                'type'        => 'ID',
283✔
30
                                                'description' => __( 'Meta ID.', 'wp-graphql-woocommerce' ),
283✔
31
                                                'resolve'     => static function ( $source ) {
283✔
32
                                                        return ! empty( $source->id ) ? $source->id : null;
2✔
33
                                                },
283✔
34
                                        ],
283✔
35
                                        'key'   => [
283✔
36
                                                'type'        => [ 'non_null' => 'String' ],
283✔
37
                                                'description' => __( 'Meta key.', 'wp-graphql-woocommerce' ),
283✔
38
                                                'resolve'     => static function ( $source ) {
283✔
39
                                                        return ! empty( $source->key ) ? (string) $source->key : null;
21✔
40
                                                },
283✔
41
                                        ],
283✔
42
                                        'value' => [
283✔
43
                                                'type'        => 'String',
283✔
44
                                                'description' => __( 'Meta value.', 'wp-graphql-woocommerce' ),
283✔
45
                                                'resolve'     => static function ( $source ) {
283✔
46
                                                        if ( empty( $source->value ) ) {
21✔
47
                                                                return null;
×
48
                                                        }
49

50
                                                        if ( is_array( $source->value ) || is_object( $source->value ) ) {
21✔
UNCOV
51
                                                                return wp_json_encode( $source->value );
×
52
                                                        }
53

54
                                                        return (string) $source->value;
21✔
55
                                                },
283✔
56
                                        ],
283✔
57
                                ],
283✔
58
                        ]
283✔
59
                );
283✔
60
        }
61

62
        /**
63
         * Definition/Resolution of the metaData field used across the schema.
64
         *
65
         * @return array
66
         */
67
        public static function get_metadata_field_definition() {
68
                return [
283✔
69
                        'type'        => [ 'list_of' => 'MetaData' ],
283✔
70
                        'description' => __( 'Object meta data', 'wp-graphql-woocommerce' ),
283✔
71
                        'args'        => [
283✔
72
                                'key'      => [
283✔
73
                                        'type'        => 'String',
283✔
74
                                        'description' => __( 'Retrieve meta by key', 'wp-graphql-woocommerce' ),
283✔
75
                                ],
283✔
76
                                'keysIn'   => [
283✔
77
                                        'type'        => [ 'list_of' => 'String' ],
283✔
78
                                        'description' => __( 'Retrieve multiple metas by key', 'wp-graphql-woocommerce' ),
283✔
79
                                ],
283✔
80
                                'multiple' => [
283✔
81
                                        'type'        => 'Boolean',
283✔
82
                                        'description' => __( 'Retrieve meta with matching keys', 'wp-graphql-woocommerce' ),
283✔
83
                                ],
283✔
84
                        ],
283✔
85
                        'resolve'     => static function ( $source, array $args ) {
283✔
86
                                // Set unique flag.
87
                                $single = empty( $args['multiple'] );
19✔
88

89
                                // Check "key" argument and format meta_data objects.
90
                                if ( ! empty( $args['key'] ) && $source->meta_exists( $args['key'] ) ) {
19✔
91
                                        $key  = $args['key'];
1✔
92
                                        $data = $source->get_meta( $key, false );
1✔
93
                                        if ( empty( $data ) ) {
1✔
94
                                                $data = [];
×
95
                                        } elseif ( $single ) {
1✔
96
                                                $data = array_slice( $data, 0, 1 );
1✔
97
                                        }
98

99
                                        $data = array_map(
1✔
100
                                                static function ( $value ) {
1✔
101
                                                        return (object) $value;
1✔
102
                                                },
1✔
103
                                                $data
1✔
104
                                        );
1✔
105
                                } elseif ( ! empty( $args['keysIn'] ) ) {
19✔
106
                                        // Check "keysIn" argument and format meta_data objects.
107
                                        $keys_in = $args['keysIn'];
1✔
108

109
                                        $found = [];
1✔
110
                                        $data  = array_filter(
1✔
111
                                                $source->get_meta_data(),
1✔
112
                                                static function ( $meta ) use ( $keys_in, $single, &$found ) {
1✔
113
                                                        if ( in_array( $meta->key, $keys_in, true ) ) {
1✔
114
                                                                if ( $single && in_array( $meta->key, $found, true ) ) {
1✔
115
                                                                        return false;
×
116
                                                                }
117
                                                                $found[] = $meta->key;
1✔
118
                                                                return true;
1✔
119
                                                        }
120
                                                }
1✔
121
                                        );
1✔
122
                                } else {
123
                                        // If no arguments set return all meta (in accordance with unique flag).
124
                                        $found = [];
19✔
125
                                        $data  = array_filter(
19✔
126
                                                $source->get_meta_data(),
19✔
127
                                                static function ( $meta ) use ( $single, &$found ) {
19✔
128
                                                        if ( $single && in_array( $meta->key, $found, true ) ) {
19✔
129
                                                                return false;
1✔
130
                                                        }
131

132
                                                        $found[] = $meta->key;
19✔
133
                                                        return true;
19✔
134
                                                }
19✔
135
                                        );
19✔
136
                                }//end if
137

138
                                return ! empty( $data ) ? $data : null;
19✔
139
                        },
283✔
140
                ];
283✔
141
        }
142
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc