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

wp-graphql / wp-graphql / 14716683875

28 Apr 2025 07:58PM UTC coverage: 84.287% (+1.6%) from 82.648%
14716683875

push

github

actions-user
release: merge develop into master for v2.3.0

15905 of 18870 relevant lines covered (84.29%)

257.23 hits per line

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

71.43
/src/Type/Union/TermObjectUnion.php
1
<?php
2
namespace WPGraphQL\Type\Union;
3

4
use WPGraphQL\Registry\TypeRegistry;
5

6
/**
7
 * Class TermObjectUnion
8
 *
9
 * @package WPGraphQL\Type\Union
10
 * @deprecated use TermNode interface instead
11
 */
12
class TermObjectUnion {
13

14
        /**
15
         * Registers the Type
16
         *
17
         * @param \WPGraphQL\Registry\TypeRegistry $type_registry
18
         *
19
         * @throws \Exception
20
         */
21
        public static function register_type( TypeRegistry $type_registry ): void {
593✔
22
                register_graphql_union_type(
593✔
23
                        'TermObjectUnion',
593✔
24
                        [
593✔
25
                                'kind'        => 'union',
593✔
26
                                'typeNames'   => self::get_possible_types(),
593✔
27
                                'description' => static function () {
593✔
28
                                        return __( 'Union between the Category, Tag and PostFormatPost types', 'wp-graphql' );
×
29
                                },
593✔
30
                                'resolveType' => static function ( $value ) use ( $type_registry ) {
593✔
31
                                        _doing_it_wrong( 'TermObjectUnion', esc_attr__( 'The TermObjectUnion GraphQL type is deprecated. Use the TermNode interface instead.', 'wp-graphql' ), '1.14.1' );
×
32

33
                                        $type = null;
×
34
                                        if ( isset( $value->taxonomyName ) ) {
×
35
                                                $tax_object = get_taxonomy( $value->taxonomyName );
×
36
                                                if ( isset( $tax_object->graphql_single_name ) ) {
×
37
                                                        $type = $type_registry->get_type( $tax_object->graphql_single_name );
×
38
                                                }
39
                                        }
40

41
                                        return ! empty( $type ) ? $type : null;
×
42
                                },
593✔
43
                        ]
593✔
44
                );
593✔
45
        }
46

47
        /**
48
         * Returns a list of possible types for the union
49
         *
50
         * @return array<string,string>
51
         */
52
        public static function get_possible_types() {
593✔
53
                $possible_types     = [];
593✔
54
                $allowed_taxonomies = \WPGraphQL::get_allowed_taxonomies( 'objects', [ 'graphql_kind' => 'object' ] );
593✔
55

56
                foreach ( $allowed_taxonomies as $tax_object ) {
593✔
57
                        if ( empty( $possible_types[ $tax_object->name ] ) ) {
593✔
58
                                if ( isset( $tax_object->graphql_single_name ) ) {
593✔
59
                                        $possible_types[ $tax_object->name ] = $tax_object->graphql_single_name;
593✔
60
                                }
61
                        }
62
                }
63

64
                return $possible_types;
593✔
65
        }
66
}
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

© 2025 Coveralls, Inc