• 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

70.37
/src/Type/Union/PostObjectUnion.php
1
<?php
2

3
namespace WPGraphQL\Type\Union;
4

5
use WPGraphQL\Registry\TypeRegistry;
6

7
/**
8
 * Class PostObjectUnion
9
 *
10
 * @package WPGraphQL\Type\Union
11
 * @deprecated use ContentNode interface instead
12
 */
13
class PostObjectUnion {
14

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

34
                                        $type = null;
×
35
                                        if ( isset( $value->post_type ) ) {
×
36
                                                $post_type_object = get_post_type_object( $value->post_type );
×
37
                                                if ( isset( $post_type_object->graphql_single_name ) ) {
×
38
                                                        $type = $type_registry->get_type( $post_type_object->graphql_single_name );
×
39
                                                }
40
                                        }
41

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

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

57
                foreach ( $allowed_post_types as $post_type_object ) {
593✔
58
                        if ( empty( $possible_types[ $post_type_object->name ] ) && isset( $post_type_object->graphql_single_name ) ) {
593✔
59
                                $possible_types[ $post_type_object->name ] = $post_type_object->graphql_single_name;
593✔
60
                        }
61
                }
62

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