1
1
<?php
2
2
/**
3
- * Filters
4
- *
5
- * Filter callbacks for executing filters on the GraphQL Schema
3
+ * Adds filters that modify core schema.
6
4
*
7
5
* @package \WPGraphQL\Extensions\WooCommerce
8
6
* @since 0.0.1
12
10
13
11
use WPGraphQL \Extensions \WooCommerce \Data \Connection \Post_Connection_Resolver ;
14
12
use WPGraphQL \Extensions \WooCommerce \Data \Connection \WC_Terms_Connection_Resolver ;
15
- use WPGraphQL \Extensions \WooCommerce \Data \Factory ;
16
13
use WPGraphQL \Extensions \WooCommerce \Data \Loader \WC_Customer_Loader ;
17
14
use WPGraphQL \Extensions \WooCommerce \Data \Loader \WC_Post_Crud_Loader ;
18
- use WPGraphQL \Extensions \WooCommerce \Utils \QL_Session_Handler ;
19
15
20
16
/**
21
- * Class Filters
17
+ * Class Core_Schema_Filters
22
18
*/
23
- class Filters {
19
+ class Core_Schema_Filters {
24
20
/**
25
21
* Stores instance WC_Customer_Loader
26
22
*
@@ -35,24 +31,17 @@ class Filters {
35
31
*/
36
32
private static $ post_crud_loader ;
37
33
38
- /**
39
- * Stores instance session header name.
40
- *
41
- * @var string
42
- */
43
- private static $ session_header ;
44
-
45
34
/**
46
35
* Register filters
47
36
*/
48
- public static function load () {
37
+ public static function add_filters () {
49
38
// Registers WooCommerce taxonomies.
50
39
add_filter ( 'register_taxonomy_args ' , array ( __CLASS__ , 'register_taxonomy_args ' ), 10 , 2 );
51
40
52
41
// Add data-loaders to AppContext.
53
42
add_filter ( 'graphql_data_loaders ' , array ( __CLASS__ , 'graphql_data_loaders ' ), 10 , 2 );
54
43
55
- // Filter core connection resolutions.
44
+ // Adds connection resolutions for WooGraphQL type to WPGraphQL type connections .
56
45
add_filter (
57
46
'graphql_post_object_connection_query_args ' ,
58
47
array ( __CLASS__ , 'graphql_post_object_connection_query_args ' ),
@@ -65,15 +54,6 @@ public static function load() {
65
54
10 ,
66
55
5
67
56
);
68
-
69
- // Setup QL session handler.
70
- if ( ! defined ( 'NO_QL_SESSION_HANDLER ' ) ) {
71
- self ::$ session_header = apply_filters ( 'woocommerce_session_header_name ' , 'woocommerce-session ' );
72
- add_filter ( 'woocommerce_cookie ' , array ( __CLASS__ , 'woocommerce_cookie ' ) );
73
- add_filter ( 'woocommerce_session_handler ' , array ( __CLASS__ , 'init_ql_session_handler ' ) );
74
- add_filter ( 'graphql_response_headers_to_send ' , array ( __CLASS__ , 'add_session_header_to_expose_headers ' ) );
75
- add_filter ( 'graphql_access_control_allow_headers ' , array ( __CLASS__ , 'add_session_header_to_allow_headers ' ) );
76
- }
77
57
}
78
58
79
59
/**
@@ -204,55 +184,4 @@ public static function graphql_post_object_connection_query_args( $query_args, $
204
184
public static function graphql_term_object_connection_query_args ( $ query_args , $ source , $ args , $ context , $ info ) {
205
185
return WC_Terms_Connection_Resolver::get_query_args ( $ query_args , $ source , $ args , $ context , $ info );
206
186
}
207
-
208
- /**
209
- * Filters WooCommerce cookie key to be used as a HTTP Header on GraphQL HTTP requests
210
- *
211
- * @param string $cookie WooCommerce cookie key.
212
- *
213
- * @return string
214
- */
215
- public static function woocommerce_cookie ( $ cookie ) {
216
- return self ::$ session_header ;
217
- }
218
-
219
- /**
220
- * Filters WooCommerce session handler class on GraphQL HTTP requests
221
- *
222
- * @param string $session_class Classname of the current session handler class.
223
- *
224
- * @return string
225
- */
226
- public static function init_ql_session_handler ( $ session_class ) {
227
- return QL_Session_Handler::class;
228
- }
229
-
230
- /**
231
- * Append session header to the exposed headers in GraphQL responses
232
- *
233
- * @param array $headers GraphQL responser headers.
234
- *
235
- * @return array
236
- */
237
- public static function add_session_header_to_expose_headers ( $ headers ) {
238
- if ( empty ( $ headers ['Access-Control-Expose-Headers ' ] ) ) {
239
- $ headers ['Access-Control-Expose-Headers ' ] = apply_filters ( 'woocommerce_cookie ' , self ::$ session_header );
240
- } else {
241
- $ headers ['Access-Control-Expose-Headers ' ] .= ', ' . apply_filters ( 'woocommerce_cookie ' , self ::$ session_header );
242
- }
243
-
244
- return $ headers ;
245
- }
246
-
247
- /**
248
- * Append the session header to the allowed headers in GraphQL responses
249
- *
250
- * @param array $allowed_headers The existing allowed headers.
251
- *
252
- * @return array
253
- */
254
- public static function add_session_header_to_allow_headers ( array $ allowed_headers ) {
255
- $ allowed_headers [] = self ::$ session_header ;
256
- return $ allowed_headers ;
257
- }
258
187
}
0 commit comments