Skip to content

Commit f5f3de1

Browse files
committed
Deprecated "By" queries removed. More connection resolver cleanup.
1 parent 8ad2723 commit f5f3de1

23 files changed

+107
-249
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"autoload": {
3434
"files":[
35-
"includes/connection/common-post-type-args.php",
35+
"includes/connection/wc-cpt-connection-args.php",
3636
"includes/functions.php"
3737
],
3838
"psr-4": {

includes/connection/class-coupons.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static function get_connection_config( $args = array() ): array {
6565
*/
6666
public static function get_connection_args(): array {
6767
return array_merge(
68-
get_common_post_type_args(),
68+
get_wc_cpt_connection_args(),
6969
array(
7070
'code' => array(
7171
'type' => 'String',

includes/connection/class-orders.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static function get_connection_args( $access = 'public' ): array {
7272
switch ( $access ) {
7373
case 'private':
7474
return array_merge(
75-
get_common_post_type_args(),
75+
get_wc_cpt_connection_args(),
7676
array(
7777
'statuses' => array(
7878
'type' => array( 'list_of' => 'OrderStatusEnum' ),

includes/connection/class-products.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,6 @@ public static function get_connection_args(): array {
274274
);
275275
}
276276

277-
return array_merge( get_common_post_type_args(), $args );
277+
return array_merge( get_wc_cpt_connection_args(), $args );
278278
}
279279
}

includes/connection/class-refunds.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static function get_connection_config( $args = array() ): array {
6666
*/
6767
public static function get_connection_args(): array {
6868
return array_merge(
69-
get_common_post_type_args(),
69+
get_wc_cpt_connection_args(),
7070
array(
7171
'statuses' => array(
7272
'type' => array( 'list_of' => 'String' ),

includes/connection/common-post-type-args.php renamed to includes/connection/wc-cpt-connection-args.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Define common arguments for post-type connections.
3+
* Define common connection arguments for CPT connections.
44
*
55
* @package WPGraphQL\WooCommerce\Connection
66
* @since 0.2.2
@@ -9,11 +9,11 @@
99
namespace WPGraphQL\WooCommerce\Connection;
1010

1111
/**
12-
* Returns argument definitions for argument common on all post-type connections.
12+
* Returns argument definitions for argument common on CPT connections.
1313
*
1414
* @return array
1515
*/
16-
function get_common_post_type_args(): array {
16+
function get_wc_cpt_connection_args(): array {
1717
return array(
1818
'search' => array(
1919
'type' => 'String',

includes/data/connection/class-cart-item-connection-resolver.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
*/
2323
class Cart_Item_Connection_Resolver extends AbstractConnectionResolver {
2424
/**
25-
* Include shared connection functions.
25+
* Include Db Loader connection common functions.
2626
*/
27-
use WC_Connection_Functions;
27+
use WC_Db_Loader_Common;
2828

2929
const PREFIX = 'CI';
3030

@@ -132,8 +132,7 @@ public function get_offset() {
132132
/**
133133
* Create cursor for downloadable item node.
134134
*
135-
* @param array $node Cart item.
136-
* @param string $key Cart item key.
135+
* @param string $id Cart item key.
137136
*
138137
* @return string
139138
*/
@@ -151,14 +150,15 @@ public function get_ids() {
151150
}
152151

153152
/**
154-
* Wrapper for "WC_Connection_Functions::is_valid_cart_item_offset()"
153+
* Check if cart item key is valid by confirming the validity of
154+
* the cart item in the cart encoded into cart item key.
155155
*
156-
* @param integer $offset Post ID.
156+
* @param string $offset Cart item key.
157157
*
158158
* @return bool
159159
*/
160160
public function is_valid_offset( $offset ) {
161-
return $this->is_valid_cart_item_offset( $offset );
161+
return ! empty( $this->source->get_cart_item( $offset ) );
162162
}
163163

164164
/**

includes/data/connection/class-coupon-connection-resolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
*/
2222
class Coupon_Connection_Resolver extends AbstractConnectionResolver {
2323
/**
24-
* Include shared connection functions.
24+
* Include CPT Loader connection common functions.
2525
*/
26-
use WC_Connection_Functions;
26+
use WC_CPT_Loader_Common;
2727

2828
/**
2929
* The name of the post type, or array of post types the connection resolver is resolving for

includes/data/connection/class-customer-connection-resolver.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
* Class Customer_Connection_Resolver
1919
*/
2020
class Customer_Connection_Resolver extends AbstractConnectionResolver {
21-
/**
22-
* Include shared connection functions.
23-
*/
24-
use WC_Connection_Functions;
25-
2621
/**
2722
* Return the name of the loader to be used with the connection resolver
2823
*
@@ -224,13 +219,21 @@ public function sanitize_input_fields( array $where_args ) {
224219
}
225220

226221
/**
227-
* Wrapper for "WC_Connection_Functions::is_valid_user_offset()"
222+
* Determine whether or not the the offset is valid, i.e the user corresponding to the offset exists.
223+
* Offset is equivalent to user_id. So this function is equivalent
224+
* to checking if the user with the given ID exists.
228225
*
229-
* @param integer $offset User ID.
226+
* @param integer $offset User ID.
230227
*
231228
* @return bool
232229
*/
233230
public function is_valid_offset( $offset ) {
234-
return $this->is_valid_user_offset( $offset );
231+
global $wpdb;
232+
233+
if ( ! empty( wp_cache_get( $offset, 'users' ) ) ) {
234+
return true;
235+
}
236+
237+
return $wpdb->get_var( $wpdb->prepare( "SELECT EXISTS (SELECT 1 FROM $wpdb->users WHERE ID = %d)", $offset ) );
235238
}
236239
}

includes/data/connection/class-downloadable-item-connection-resolver.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
*/
2424
class Downloadable_Item_Connection_Resolver extends AbstractConnectionResolver {
2525
/**
26-
* Include shared connection functions.
26+
* Include Db Loader connection common functions.
2727
*/
28-
use WC_Connection_Functions;
28+
use WC_Db_Loader_Common;
2929

3030
const PREFIX = 'DI';
3131

@@ -172,8 +172,7 @@ public function get_offset() {
172172
/**
173173
* Create cursor for downloadable item node.
174174
*
175-
* @param array $node Cart item.
176-
* @param string $key Cart item key.
175+
* @param string $id Downloadable item ID.
177176
*
178177
* @return string
179178
*/
@@ -211,7 +210,7 @@ public function is_valid_offset( $offset ) {
211210
*
212211
* @return bool
213212
*/
214-
protected function is_valid_model( array $model ) {
213+
protected function is_valid_model( $model ) {
215214
return isset( $model ) && ! empty( $model['download_id'] );
216215
}
217216
}

0 commit comments

Comments
 (0)