Skip to content

Commit d9d968a

Browse files
authored
fix: product connection resolution refactored to better work with the ProductQuery class (wp-graphql#880)
* fix: product connection resolution refactored to better work with the ProductQuery class * chore: Linter and PHPStan compliance met * devops: New product connection tests implemented and passing * fix: products connection pricing filters fixed * devops: CartTransactionQueueCest skipped until failing PHP version removed from CI matrix
1 parent a37c68e commit d9d968a

24 files changed

+1304
-794
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
},
2727
"require-dev": {
2828
"axepress/wp-graphql-cs": "^2.0.0-beta",
29-
"axepress/wp-graphql-stubs": "~1.16.0",
30-
"php-stubs/woocommerce-stubs": "7.9.0",
29+
"axepress/wp-graphql-stubs": "^1.27.1",
30+
"php-stubs/woocommerce-stubs": "9.1.0",
3131
"phpstan/extension-installer": "^1.3",
3232
"phpstan/phpdoc-parser": "^1.22.0",
3333
"phpstan/phpstan": "^1.10",

composer.lock

Lines changed: 64 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/connection/class-customers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $
201201
* @return array
202202
*/
203203
public static function upgrade_models( $connection, $resolver ) {
204-
if ( 'customers' === $resolver->get_info()->fieldName ) { // @phpstan-ignore-line
204+
if ( 'customers' === $resolver->get_info()->fieldName ) {
205205
$nodes = [];
206206
$edges = [];
207207
foreach ( $connection['nodes'] as $node ) {

includes/connection/class-orders.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static function register_connections() {
9999
* @param \WPGraphQL\WooCommerce\Data\Connection\Order_Connection_Resolver $resolver Connection resolver.
100100
* @param \WC_Customer $customer Customer object of querying user.
101101
*
102-
* @return array
102+
* @return array|\GraphQL\Deferred
103103
*/
104104
private static function get_customer_order_connection( $resolver, $customer ) {
105105
// If not "billing email" or "ID" set bail early by returning an empty connection.
@@ -129,7 +129,7 @@ private static function get_customer_order_connection( $resolver, $customer ) {
129129
* @param \WPGraphQL\WooCommerce\Data\Connection\Order_Connection_Resolver $resolver Connection resolver.
130130
* @param \WC_Customer $customer Customer object of querying user.
131131
*
132-
* @return array
132+
* @return array|\GraphQL\Deferred
133133
*/
134134
private static function get_customer_refund_connection( $resolver, $customer ) {
135135
$empty_results = [

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ public function get_query_args() {
6464
/**
6565
* Filter the $query_args to allow folks to customize queries programmatically.
6666
*
67-
* @param array $query_args The args that will be passed to the WP_Query.
68-
* @param mixed $source The source that's passed down the GraphQL queries.
69-
* @param array $args The inputArgs on the field.
70-
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree.
67+
* @param array $query_args The args that will be passed to the WP_Query.
68+
* @param mixed $source The source that's passed down the GraphQL queries.
69+
* @param array<string, mixed>|null $args The inputArgs on the field.
70+
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree.
7171
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo passed down the GraphQL tree.
7272
*/
7373
$query_args = apply_filters( 'graphql_cart_item_connection_query_args', $query_args, $this->source, $this->args, $this->context, $this->info );

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ public function get_query_args() {
159159
/**
160160
* Filter the $query args to allow folks to customize queries programmatically
161161
*
162-
* @param array $query_args The args that will be passed to the WP_Query
163-
* @param mixed $source The source that's passed down the GraphQL queries
164-
* @param array $args The inputArgs on the field
165-
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree
162+
* @param array $query_args The args that will be passed to the WP_Query
163+
* @param mixed $source The source that's passed down the GraphQL queries
164+
* @param array<string, mixed>|null $args The inputArgs on the field
165+
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree
166166
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo passed down the GraphQL tree
167167
*/
168168
$query_args = apply_filters( 'graphql_coupon_connection_query_args', $query_args, $this->source, $this->args, $this->context, $this->info );
@@ -178,7 +178,9 @@ public function get_query_args() {
178178
* @return \WP_Query
179179
*/
180180
public function get_query() {
181-
$query = new \WP_Query( $this->query_args );
181+
/** @var array $query_args */
182+
$query_args = $this->query_args;
183+
$query = new \WP_Query( $query_args );
182184

183185
if ( isset( $query->query_vars['suppress_filters'] ) && true === $query->query_vars['suppress_filters'] ) {
184186
throw new InvariantViolation( __( 'WP_Query has been modified by a plugin or theme to suppress_filters, which will cause issues with WPGraphQL Execution. If you need to suppress filters for a specific reason within GraphQL, consider registering a custom field to the WPGraphQL Schema with a custom resolver.', 'wp-graphql-woocommerce' ) );
@@ -237,13 +239,13 @@ public function sanitize_input_fields( array $where_args ) {
237239
* This allows plugins/themes to hook in and alter what $args should be allowed to be passed
238240
* from a GraphQL Query to the WP_Query
239241
*
240-
* @param array $args The mapped query arguments
241-
* @param array $where_args Query "where" args
242-
* @param mixed $source The query results for a query calling this
243-
* @param array $all_args All of the arguments for the query (not just the "where" args)
244-
* @param \WPGraphQL\AppContext $context The AppContext object
242+
* @param array $args The mapped query arguments
243+
* @param array $where_args Query "where" args
244+
* @param mixed $source The query results for a query calling this
245+
* @param array<string, mixed>|null $all_args All of the arguments for the query (not just the "where" args)
246+
* @param \WPGraphQL\AppContext $context The AppContext object
245247
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo object
246-
* @param mixed|string|array $post_type The post type for the query
248+
* @param mixed|string|array $post_type The post type for the query
247249
*/
248250
$args = apply_filters(
249251
'graphql_map_input_fields_to_coupon_query',

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ public function get_query_args() {
9191
/**
9292
* Filter the $query_args to allow folks to customize queries programmatically.
9393
*
94-
* @param array $query_args The args that will be passed to the WP_Query.
95-
* @param mixed $source The source that's passed down the GraphQL queries.
96-
* @param array $args The inputArgs on the field.
97-
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree.
94+
* @param array $query_args The args that will be passed to the WP_Query.
95+
* @param mixed $source The source that's passed down the GraphQL queries.
96+
* @param array<string, mixed>|null $args The inputArgs on the field.
97+
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree.
9898
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo passed down the GraphQL tree.
9999
*/
100100
$query_args = apply_filters( 'graphql_downloadable_item_connection_query_args', $query_args, $this->source, $this->args, $this->context, $this->info );

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ public function get_query_args() {
182182
/**
183183
* Filter the $query args to allow folks to customize queries programmatically
184184
*
185-
* @param array $query_args The args that will be passed to the WP_Query
186-
* @param mixed $source The source that's passed down the GraphQL queries
187-
* @param array $args The inputArgs on the field
188-
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree
185+
* @param array $query_args The args that will be passed to the WP_Query
186+
* @param mixed $source The source that's passed down the GraphQL queries
187+
* @param array<string, mixed>|null $args The inputArgs on the field
188+
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree
189189
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo passed down the GraphQL tree
190190
*/
191191
$query_args = apply_filters( 'graphql_order_connection_query_args', $query_args, $this->source, $this->args, $this->context, $this->info );
@@ -201,7 +201,9 @@ public function get_query_args() {
201201
* @return \WC_Order_Query
202202
*/
203203
public function get_query() {
204-
$query = new \WC_Order_Query( $this->query_args );
204+
/** @var array<string, mixed> $query_args */
205+
$query_args = $this->query_args;
206+
$query = new \WC_Order_Query( $query_args );
205207

206208
if ( true === $query->get( 'suppress_filters', false ) ) {
207209
throw new InvariantViolation( __( 'WC_Order_Query has been modified by a plugin or theme to suppress_filters, which will cause issues with WPGraphQL Execution. If you need to suppress filters for a specific reason within GraphQL, consider registering a custom field to the WPGraphQL Schema with a custom resolver.', 'wp-graphql-woocommerce' ) );
@@ -335,13 +337,13 @@ public function sanitize_input_fields( array $where_args ) {
335337
* This allows plugins/themes to hook in and alter what $args should be allowed to be passed
336338
* from a GraphQL Query to the WP_Query
337339
*
338-
* @param array $args The mapped query arguments
339-
* @param array $where_args Query "where" args
340-
* @param mixed $source The query results for a query calling this
341-
* @param array $all_args All of the arguments for the query (not just the "where" args)
342-
* @param \WPGraphQL\AppContext $context The AppContext object
340+
* @param array $args The mapped query arguments
341+
* @param array $where_args Query "where" args
342+
* @param mixed $source The query results for a query calling this
343+
* @param array<string, mixed>|null $all_args All of the arguments for the query (not just the "where" args)
344+
* @param \WPGraphQL\AppContext $context The AppContext object
343345
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo object
344-
* @param mixed|string|array $post_type The post type for the query
346+
* @param mixed|string|array $post_type The post type for the query
345347
*/
346348
$args = apply_filters(
347349
'graphql_map_input_fields_to_order_query',

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public function get_query_args() {
4545
/**
4646
* Filter the $query_args to allow folks to customize queries programmatically.
4747
*
48-
* @param array $query_args The args that will be passed to the WP_Query.
49-
* @param mixed $source The source that's passed down the GraphQL queries.
50-
* @param array $args The inputArgs on the field.
51-
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree.
48+
* @param array $query_args The args that will be passed to the WP_Query.
49+
* @param mixed $source The source that's passed down the GraphQL queries.
50+
* @param array<string, mixed>|null $args The inputArgs on the field.
51+
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree.
5252
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo passed down the GraphQL tree.
5353
*/
5454
$query_args = apply_filters( 'graphql_order_item_connection_query_args', $query_args, $this->source, $this->args, $this->context, $this->info );
@@ -80,10 +80,10 @@ public function get_query() {
8080
/**
8181
* Filter the $item_type to allow non-core item types.
8282
*
83-
* @param string $item_type Order item type.
84-
* @param mixed $source The source that's passed down the GraphQL queries.
85-
* @param array $args The inputArgs on the field.
86-
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree.
83+
* @param string $item_type Order item type.
84+
* @param mixed $source The source that's passed down the GraphQL queries.
85+
* @param array<string, mixed>|null $args The inputArgs on the field.
86+
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree.
8787
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo passed down the GraphQL tree.
8888
*/
8989
$type = apply_filters(
@@ -143,7 +143,7 @@ public function get_query() {
143143

144144
// Cache items for later.
145145
foreach ( $items as $item ) {
146-
$this->loader->prime(
146+
$this->get_loader()->prime(
147147
$item->get_id(),
148148
new \WPGraphQL\WooCommerce\Model\Order_Item( $item, $this->source )
149149
);

0 commit comments

Comments
 (0)