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

rtCamp / snapwp-helper / 13591022249

28 Feb 2025 03:15PM UTC coverage: 82.291% (-1.3%) from 83.585%
13591022249

push

github

web-flow
dev!: Replace `EnqueuedScript.location` with `EnqueuedScript.groupLocation` (#80)

* fix: replace EnqueuedScript.location with EnqueuedScript.groupLocation

* fix: register groupLocation only if WPGraphQL doesn't register it itself

* fix: Update tests for groupLocation & docs nitpicks

* fix: Handle both enum cases

* feat!: Change `ScriptModuleDependency.importType` to `ScriptModuleImportTypeEnum`.

* feat: use AbstractEnum class

* fix: register the enum

---------

Co-authored-by: Dovid Levine <david@axepress.dev>

1566 of 1903 relevant lines covered (82.29%)

13.03 hits per line

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

16.67
/src/Modules/GraphQL/Type/Fields/EnqueuedScript.php
1
<?php
2
/**
3
 * Registers custom fields to the GraphQL EnqueuedScript Object.
4
 *
5
 * @todo Remove when WPGraphQL >= 1.30.0 is required.
6
 *
7
 * @see https://github.com/wp-graphql/wp-graphql/pull/3196
8
 *
9
 * @package SnapWP\Helper\Modules\GraphQL\Type\Fields
10
 */
11

12
declare( strict_types = 1 );
13

14
namespace SnapWP\Helper\Modules\GraphQL\Type\Fields;
15

16
/**
17
 * Class - EnqueuedScript
18
 */
19
final class EnqueuedScript extends AbstractFields {
20
        /**
21
         * {@inheritDoc}
22
         */
23
        public static function get_type_name(): string {
×
24
                return 'EnqueuedScript';
×
25
        }
26

27
        /**
28
         * {@inheritDoc}
29
         */
30
        public function register(): void {
35✔
31
                // Early return if WPGraphQL will register the field itself.
32
                if ( defined( 'WPGRAPHQL_VERSION' ) && version_compare( WPGRAPHQL_VERSION, '1.30.0', '>=' ) ) {
35✔
33
                        return;
35✔
34
                }
35

36
                parent::register();
×
37
        }
38

39
        /**
40
         * {@inheritDoc}
41
         */
42
        public function get_fields(): array {
×
43
                return [
×
44
                        'groupLocation' => [
×
45
                                'type'        => 'ScriptLoadingGroupLocationEnum',
×
46
                                'description' => __( 'The location where this script should be loaded', 'snapwp-helper' ),
×
47
                                'resolve'     => static function ( \_WP_Dependency $script ) {
×
48
                                        if ( isset( $script->extra['group'] ) && 1 === (int) $script->extra['group'] ) {
×
49
                                                return 'footer';
×
50
                                        }
51

52
                                        return 'header';
×
53
                                },
×
54
                        ],
×
55
                ];
×
56
        }
57
}
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