• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

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

90.55
/src/Type/InterfaceType/EnqueuedAsset.php
1
<?php
2
namespace WPGraphQL\Type\InterfaceType;
3

4
use WPGraphQL\Registry\TypeRegistry;
5

6
/**
7
 * Class EnqueuedAsset
8
 *
9
 * @package WPGraphQL\Type
10
 */
11
class EnqueuedAsset {
12

13
        /**
14
         * Register the Enqueued Script Type
15
         *
16
         * @param \WPGraphQL\Registry\TypeRegistry $type_registry The WPGraphQL Type Registry
17
         *
18
         * @return void
19
         */
20
        public static function register_type( TypeRegistry $type_registry ) {
593✔
21
                register_graphql_interface_type(
593✔
22
                        'EnqueuedAsset',
593✔
23
                        [
593✔
24
                                'description' => static function () {
593✔
25
                                        return __( 'A script or stylesheet resource that should be loaded by the client. Contains information about the resource\'s location, dependencies, and loading behavior.', 'wp-graphql' );
15✔
26
                                },
593✔
27
                                'resolveType' => static function ( $asset ) use ( $type_registry ) {
593✔
28

29
                                        /**
30
                                         * The resolveType callback is used at runtime to determine what Type an object
31
                                         * implementing the EnqueuedAsset Interface should be resolved as.
32
                                         *
33
                                         * You can filter this centrally using the "graphql_wp_interface_type_config" filter
34
                                         * to override if you need something other than a Post object to be resolved via the
35
                                         * $post->post_type attribute.
36
                                         */
37
                                        $type = null;
×
38

39
                                        if ( isset( $asset['type'] ) ) {
×
40
                                                $type = $type_registry->get_type( $asset['type'] );
×
41
                                        }
42

43
                                        return ! empty( $type ) ? $type : null;
×
44
                                },
593✔
45
                                'fields'      => static function () {
593✔
46
                                        return [
162✔
47
                                                'args'         => [
162✔
48
                                                        'type'              => 'Boolean',
162✔
49
                                                        'description'       => static function () {
162✔
50
                                                                return __( 'Deprecated', 'wp-graphql' );
15✔
51
                                                        },
162✔
52
                                                        'deprecationReason' => static function () {
162✔
53
                                                                return __( 'Use `EnqueuedAsset.media` instead.', 'wp-graphql' );
15✔
54
                                                        },
162✔
55
                                                ],
162✔
56
                                                'after'        => [
162✔
57
                                                        'type'        => [ 'list_of' => 'String' ],
162✔
58
                                                        'description' => static function () {
162✔
59
                                                                return __( 'The inline code to be run after the asset is loaded.', 'wp-graphql' );
15✔
60
                                                        },
162✔
61
                                                        'resolve'     => static function ( \_WP_Dependency $asset ) {
162✔
62
                                                                if ( empty( $asset->extra['after'] ) ) {
3✔
63
                                                                        return null;
3✔
64
                                                                }
65

66
                                                                $after_scripts = array_map(
1✔
67
                                                                        static function ( $after ) {
1✔
68
                                                                                return is_string( $after ) ? $after : null;
1✔
69
                                                                        },
1✔
70
                                                                        $asset->extra['after']
1✔
71
                                                                );
1✔
72

73
                                                                return array_filter( $after_scripts );
1✔
74
                                                        },
162✔
75
                                                ],
162✔
76
                                                'before'       => [
162✔
77
                                                        'type'        => [ 'list_of' => 'String' ],
162✔
78
                                                        'description' => static function () {
162✔
79
                                                                return __( 'The inline code to be run before the asset is loaded.', 'wp-graphql' );
15✔
80
                                                        },
162✔
81
                                                        'resolve'     => static function ( \_WP_Dependency $asset ) {
162✔
82
                                                                if ( empty( $asset->extra['before'] ) ) {
3✔
83
                                                                        return null;
3✔
84
                                                                }
85

86
                                                                $before_scripts = array_map(
×
87
                                                                        static function ( $before ) {
×
88
                                                                                return is_string( $before ) ? $before : null;
×
89
                                                                        },
×
90
                                                                        $asset->extra['before']
×
91
                                                                );
×
92

93
                                                                return array_filter( $before_scripts );
×
94
                                                        },
162✔
95
                                                ],
162✔
96
                                                'conditional'  => [
162✔
97
                                                        'type'        => 'String',
162✔
98
                                                        'description' => static function () {
162✔
99
                                                                return __( 'The HTML conditional comment for the enqueued asset. E.g. IE 6, lte IE 7, etc', 'wp-graphql' );
15✔
100
                                                        },
162✔
101
                                                        'resolve'     => static function ( \_WP_Dependency $asset ) {
162✔
102
                                                                if ( ! isset( $asset->extra['conditional'] ) || ! is_string( $asset->extra['conditional'] ) ) {
6✔
103
                                                                        return null;
6✔
104
                                                                }
105

106
                                                                return $asset->extra['conditional'];
2✔
107
                                                        },
162✔
108
                                                ],
162✔
109
                                                'dependencies' => [
162✔
110
                                                        'type'        => [ 'list_of' => 'EnqueuedAsset' ],
162✔
111
                                                        'description' => static function () {
162✔
112
                                                                return __( 'Dependencies needed to use this asset', 'wp-graphql' );
15✔
113
                                                        },
162✔
114
                                                ],
162✔
115
                                                'id'           => [
162✔
116
                                                        'type'        => [ 'non_null' => 'ID' ],
162✔
117
                                                        'description' => static function () {
162✔
118
                                                                return __( 'The ID of the enqueued asset', 'wp-graphql' );
15✔
119
                                                        },
162✔
120
                                                ],
162✔
121
                                                'handle'       => [
162✔
122
                                                        'type'        => 'String',
162✔
123
                                                        'description' => static function () {
162✔
124
                                                                return __( 'The handle of the enqueued asset', 'wp-graphql' );
15✔
125
                                                        },
162✔
126
                                                ],
162✔
127
                                                'src'          => [
162✔
128
                                                        'type'        => 'String',
162✔
129
                                                        'description' => static function () {
162✔
130
                                                                return __( 'The source of the asset', 'wp-graphql' );
15✔
131
                                                        },
162✔
132
                                                        'resolve'     => static function ( \_WP_Dependency $stylesheet ) {
162✔
133
                                                                return ! empty( $stylesheet->src ) && is_string( $stylesheet->src ) ? $stylesheet->src : null;
39✔
134
                                                        },
162✔
135
                                                ],
162✔
136
                                                'version'      => [
162✔
137
                                                        'type'        => 'String',
162✔
138
                                                        'description' => static function () {
162✔
139
                                                                return __( 'The version of the enqueued asset', 'wp-graphql' );
15✔
140
                                                        },
162✔
141
                                                ],
162✔
142
                                                'extra'        => [
162✔
143
                                                        'type'              => 'String',
162✔
144
                                                        'description'       => static function () {
162✔
145
                                                                return __( 'Extra information needed for the script', 'wp-graphql' );
15✔
146
                                                        },
162✔
147
                                                        'deprecationReason' => static function () {
162✔
148
                                                                return __( 'Use `EnqueuedScript.extraData` instead.', 'wp-graphql' );
15✔
149
                                                        },
162✔
150
                                                        'resolve'           => static function ( $asset ) {
162✔
151
                                                                return isset( $asset->extra['data'] ) ? $asset->extra['data'] : null;
×
152
                                                        },
162✔
153
                                                ],
162✔
154
                                                'group'        => [
162✔
155
                                                        'type'        => 'Int',
162✔
156
                                                        'description' => static function () {
162✔
157
                                                                return __( 'The loading group to which this asset belongs.', 'wp-graphql' );
15✔
158
                                                        },
162✔
159
                                                        'resolve'     => static function ( $asset ) {
162✔
160
                                                                return isset( $asset->extra['group'] ) ? (int) $asset->extra['group'] : null;
6✔
161
                                                        },
162✔
162
                                                ],
162✔
163
                                        ];
162✔
164
                                },
593✔
165
                        ]
593✔
166
                );
593✔
167
        }
168
}
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