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

AxeWP / wp-graphql-headless-login / #73

07 Jun 2025 09:33AM UTC coverage: 82.559% (-0.4%) from 82.929%
#73

push

php-coveralls

web-flow
dev: add support for lazy-loading description/deprecationReason config values (#170)

* dev: add support for lazy-loading description/deprecationReason config values

* chore: add missing mutation descriptions

* chore: update dep to release

* .

* chore: formatting

* Update src/Type/Enum/GoogleProviderPromptTypeEnum.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore: bump tested-up-to

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

121 of 163 new or added lines in 26 files covered. (74.23%)

10 existing lines in 8 files now uncovered.

2291 of 2775 relevant lines covered (82.56%)

24.03 hits per line

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

0.0
/src/WoocommerceSchemaFilters.php
1
<?php
2
/**
3
 * Adds filters that modify WooGraphQL schema.
4
 *
5
 * @package WPGraphQL\Login
6
 */
7

8
declare( strict_types = 1 );
9

10
namespace WPGraphQL\Login;
11

12
use WPGraphQL\Login\Type\WPObject\AuthenticationData;
13
use WPGraphQL\Login\Vendor\AxeWP\GraphQL\Helper\Compat;
14
use WPGraphQL\Login\Vendor\AxeWP\GraphQL\Interfaces\Registrable;
15

16
/**
17
 * Class - WoocommerceSchemaFilters
18
 */
19
class WoocommerceSchemaFilters implements Registrable {
20
        /**
21
         * {@inheritDoc}
22
         */
23
        public static function init(): void {
24
                // Bail if WPGraphQL for Woocommerce doesnt exist.
25
                if ( ! defined( 'WPGRAPHQL_WOOCOMMERCE_VERSION' ) ) {
×
26
                        return;
×
27
                }
28

29
                add_filter( 'graphql_login_user_types', [ self::class, 'add_customer_to_user_types' ] );
×
30
                add_action( 'graphql_register_types', [ self::class, 'add_fields' ] );
×
31
        }
32

33
        /**
34
         * Adds the Customer object to the list of 'User' types that get AuthenticationData.
35
         *
36
         * @param string[] $types The GraphQL type names.
37
         *
38
         * @return string[]
39
         */
40
        public static function add_customer_to_user_types( array $types ): array {
41
                $types[] = 'Customer';
×
42

43
                return $types;
×
44
        }
45

46
        /**
47
         * Adds WooGraphQL fields to the plugin GraphQL types.
48
         */
49
        public static function add_fields(): void {
50
                // Register session token to Authentication data.
51
                register_graphql_field(
×
52
                        AuthenticationData::get_type_name(),
×
53
                        'wooSessionToken',
×
54
                        // @todo remove Compat wrapper when WPGraphQL v2.3.0+ is required.
NEW
55
                        Compat::resolve_graphql_config(
×
NEW
56
                                [
×
NEW
57
                                        'type'        => 'String',
×
NEW
58
                                        'description' => static fn () => __( 'A JWT token used to identify the current WooCommerce session', 'wp-graphql-headless-login' ),
×
NEW
59
                                        'resolve'     => static function ( $user ) {
×
NEW
60
                                                if ( ! function_exists( 'WC' ) ) {
×
NEW
61
                                                        return null;
×
62
                                                }
63

NEW
64
                                                if ( get_current_user_id() !== $user->databaseId && 'guest' !== $user->id ) {
×
NEW
65
                                                        return null;
×
66
                                                }
67

68
                                                /** @var \WPGraphQL\WooCommerce\Utils\QL_Session_Handler $session */
NEW
69
                                                $session = \WC()->session;
×
70

71
                                                /** \WooCommerce::$session */
NEW
72
                                                return apply_filters( 'graphql_customer_session_token', $session->build_token() ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
×
NEW
73
                                        },
×
NEW
74
                                ]
×
NEW
75
                        )
×
UNCOV
76
                );
×
77

78
                /**
79
                 * In versions prior to WPGraphQL for WooCommerce v0.18.2, customer needs to be added to the LoginPayload type manually.
80
                 *
81
                 * @todo Remove this check when the minimum version of WPGraphQL for WooCommerce is > v0.18.2.
82
                 */
83
                if ( ! defined( 'WPGRAPHQL_WOOCOMMERCE_VERSION' ) || version_compare( WPGRAPHQL_WOOCOMMERCE_VERSION, '0.18.2', '<' ) ) {
×
84
                        // Register the customer and session token to the Login payloads.
85
                        register_graphql_field(
×
86
                                'LoginPayload',
×
87
                                'customer',
×
88
                                // @todo remove Compat wrapper when WPGraphQL v2.3.0+ is required.
NEW
89
                                Compat::resolve_graphql_config(
×
NEW
90
                                        [
×
NEW
91
                                                'type'        => 'Customer',
×
NEW
92
                                                'description' => static fn () => __( 'The customer object for the logged in user', 'wp-graphql-headless-login' ),
×
NEW
93
                                                'resolve'     => static function ( $payload ) {
×
NEW
94
                                                        $user_id = isset( $payload['user']->ID ) ? $payload['user']->ID : null;
×
95

NEW
96
                                                        if ( ! $user_id ) {
×
NEW
97
                                                                return null;
×
98
                                                        }
99

NEW
100
                                                        return new \WPGraphQL\WooCommerce\Model\Customer( $user_id );
×
NEW
101
                                                },
×
NEW
102
                                        ]
×
NEW
103
                                )
×
UNCOV
104
                        );
×
105
                }
106

107
                /**
108
                 * In Woocommerce 0.18.2+ the session token is registered to the `LoginPayload` as `sessionToken`.
109
                 *
110
                 * @todo Remove this check when the minimum version of WPGraphQL for WooCommerce is > v0.18.2.
111
                 */
112
                register_graphql_field(
×
113
                        'LoginPayload',
×
114
                        'wooSessionToken',
×
115
                        // @todo remove Compat wrapper when WPGraphQL v2.3.0+ is required.
NEW
116
                        Compat::resolve_graphql_config(
×
NEW
117
                                [
×
NEW
118
                                        'type'              => 'String',
×
NEW
119
                                        'description'       => static fn () => __( 'A JWT token used to identify the current WooCommerce session', 'wp-graphql-headless-login' ),
×
NEW
120
                                        'deprecationReason' => static fn () => __( 'Use `sessionToken` instead (available in WPGraphQL for WooCommerce v0.18.2+)', 'wp-graphql-headless-login' ),
×
NEW
121
                                        'resolve'           => static function () {
×
NEW
122
                                                if ( ! function_exists( 'WC' ) ) {
×
NEW
123
                                                        return null;
×
124
                                                }
125

126
                                                /** @var \WPGraphQL\WooCommerce\Utils\QL_Session_Handler $session */
NEW
127
                                                $session = \WC()->session;
×
128

129
                                                /** \WooCommerce::$session */
NEW
130
                                                return apply_filters( 'graphql_customer_session_token', $session->build_token() ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
×
NEW
131
                                        },
×
NEW
132
                                ],
×
NEW
133
                        )
×
UNCOV
134
                );
×
135
        }
136
}
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