Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: product connection resolution refactored to better work with the ProductQuery class #880

Merged
merged 5 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
},
"require-dev": {
"axepress/wp-graphql-cs": "^2.0.0-beta",
"axepress/wp-graphql-stubs": "~1.16.0",
"php-stubs/woocommerce-stubs": "7.9.0",
"axepress/wp-graphql-stubs": "^1.27.1",
"php-stubs/woocommerce-stubs": "9.1.0",
"phpstan/extension-installer": "^1.3",
"phpstan/phpdoc-parser": "^1.22.0",
"phpstan/phpstan": "^1.10",
Expand Down
126 changes: 64 additions & 62 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion includes/connection/class-customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $
* @return array
*/
public static function upgrade_models( $connection, $resolver ) {
if ( 'customers' === $resolver->get_info()->fieldName ) { // @phpstan-ignore-line
if ( 'customers' === $resolver->get_info()->fieldName ) {
$nodes = [];
$edges = [];
foreach ( $connection['nodes'] as $node ) {
Expand Down
4 changes: 2 additions & 2 deletions includes/connection/class-orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static function register_connections() {
* @param \WPGraphQL\WooCommerce\Data\Connection\Order_Connection_Resolver $resolver Connection resolver.
* @param \WC_Customer $customer Customer object of querying user.
*
* @return array
* @return array|\GraphQL\Deferred
*/
private static function get_customer_order_connection( $resolver, $customer ) {
// If not "billing email" or "ID" set bail early by returning an empty connection.
Expand Down Expand Up @@ -129,7 +129,7 @@ private static function get_customer_order_connection( $resolver, $customer ) {
* @param \WPGraphQL\WooCommerce\Data\Connection\Order_Connection_Resolver $resolver Connection resolver.
* @param \WC_Customer $customer Customer object of querying user.
*
* @return array
* @return array|\GraphQL\Deferred
*/
private static function get_customer_refund_connection( $resolver, $customer ) {
$empty_results = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public function get_query_args() {
/**
* Filter the $query_args to allow folks to customize queries programmatically.
*
* @param array $query_args The args that will be passed to the WP_Query.
* @param mixed $source The source that's passed down the GraphQL queries.
* @param array $args The inputArgs on the field.
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree.
* @param array $query_args The args that will be passed to the WP_Query.
* @param mixed $source The source that's passed down the GraphQL queries.
* @param array<string, mixed>|null $args The inputArgs on the field.
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree.
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo passed down the GraphQL tree.
*/
$query_args = apply_filters( 'graphql_cart_item_connection_query_args', $query_args, $this->source, $this->args, $this->context, $this->info );
Expand Down
24 changes: 13 additions & 11 deletions includes/data/connection/class-coupon-connection-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ public function get_query_args() {
/**
* Filter the $query args to allow folks to customize queries programmatically
*
* @param array $query_args The args that will be passed to the WP_Query
* @param mixed $source The source that's passed down the GraphQL queries
* @param array $args The inputArgs on the field
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree
* @param array $query_args The args that will be passed to the WP_Query
* @param mixed $source The source that's passed down the GraphQL queries
* @param array<string, mixed>|null $args The inputArgs on the field
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo passed down the GraphQL tree
*/
$query_args = apply_filters( 'graphql_coupon_connection_query_args', $query_args, $this->source, $this->args, $this->context, $this->info );
Expand All @@ -178,7 +178,9 @@ public function get_query_args() {
* @return \WP_Query
*/
public function get_query() {
$query = new \WP_Query( $this->query_args );
/** @var array $query_args */
$query_args = $this->query_args;
$query = new \WP_Query( $query_args );

if ( isset( $query->query_vars['suppress_filters'] ) && true === $query->query_vars['suppress_filters'] ) {
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' ) );
Expand Down Expand Up @@ -237,13 +239,13 @@ public function sanitize_input_fields( array $where_args ) {
* This allows plugins/themes to hook in and alter what $args should be allowed to be passed
* from a GraphQL Query to the WP_Query
*
* @param array $args The mapped query arguments
* @param array $where_args Query "where" args
* @param mixed $source The query results for a query calling this
* @param array $all_args All of the arguments for the query (not just the "where" args)
* @param \WPGraphQL\AppContext $context The AppContext object
* @param array $args The mapped query arguments
* @param array $where_args Query "where" args
* @param mixed $source The query results for a query calling this
* @param array<string, mixed>|null $all_args All of the arguments for the query (not just the "where" args)
* @param \WPGraphQL\AppContext $context The AppContext object
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo object
* @param mixed|string|array $post_type The post type for the query
* @param mixed|string|array $post_type The post type for the query
*/
$args = apply_filters(
'graphql_map_input_fields_to_coupon_query',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ public function get_query_args() {
/**
* Filter the $query_args to allow folks to customize queries programmatically.
*
* @param array $query_args The args that will be passed to the WP_Query.
* @param mixed $source The source that's passed down the GraphQL queries.
* @param array $args The inputArgs on the field.
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree.
* @param array $query_args The args that will be passed to the WP_Query.
* @param mixed $source The source that's passed down the GraphQL queries.
* @param array<string, mixed>|null $args The inputArgs on the field.
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree.
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo passed down the GraphQL tree.
*/
$query_args = apply_filters( 'graphql_downloadable_item_connection_query_args', $query_args, $this->source, $this->args, $this->context, $this->info );
Expand Down
24 changes: 13 additions & 11 deletions includes/data/connection/class-order-connection-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ public function get_query_args() {
/**
* Filter the $query args to allow folks to customize queries programmatically
*
* @param array $query_args The args that will be passed to the WP_Query
* @param mixed $source The source that's passed down the GraphQL queries
* @param array $args The inputArgs on the field
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree
* @param array $query_args The args that will be passed to the WP_Query
* @param mixed $source The source that's passed down the GraphQL queries
* @param array<string, mixed>|null $args The inputArgs on the field
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo passed down the GraphQL tree
*/
$query_args = apply_filters( 'graphql_order_connection_query_args', $query_args, $this->source, $this->args, $this->context, $this->info );
Expand All @@ -201,7 +201,9 @@ public function get_query_args() {
* @return \WC_Order_Query
*/
public function get_query() {
$query = new \WC_Order_Query( $this->query_args );
/** @var array<string, mixed> $query_args */
$query_args = $this->query_args;
$query = new \WC_Order_Query( $query_args );

if ( true === $query->get( 'suppress_filters', false ) ) {
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' ) );
Expand Down Expand Up @@ -335,13 +337,13 @@ public function sanitize_input_fields( array $where_args ) {
* This allows plugins/themes to hook in and alter what $args should be allowed to be passed
* from a GraphQL Query to the WP_Query
*
* @param array $args The mapped query arguments
* @param array $where_args Query "where" args
* @param mixed $source The query results for a query calling this
* @param array $all_args All of the arguments for the query (not just the "where" args)
* @param \WPGraphQL\AppContext $context The AppContext object
* @param array $args The mapped query arguments
* @param array $where_args Query "where" args
* @param mixed $source The query results for a query calling this
* @param array<string, mixed>|null $all_args All of the arguments for the query (not just the "where" args)
* @param \WPGraphQL\AppContext $context The AppContext object
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo object
* @param mixed|string|array $post_type The post type for the query
* @param mixed|string|array $post_type The post type for the query
*/
$args = apply_filters(
'graphql_map_input_fields_to_order_query',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public function get_query_args() {
/**
* Filter the $query_args to allow folks to customize queries programmatically.
*
* @param array $query_args The args that will be passed to the WP_Query.
* @param mixed $source The source that's passed down the GraphQL queries.
* @param array $args The inputArgs on the field.
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree.
* @param array $query_args The args that will be passed to the WP_Query.
* @param mixed $source The source that's passed down the GraphQL queries.
* @param array<string, mixed>|null $args The inputArgs on the field.
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree.
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo passed down the GraphQL tree.
*/
$query_args = apply_filters( 'graphql_order_item_connection_query_args', $query_args, $this->source, $this->args, $this->context, $this->info );
Expand Down Expand Up @@ -80,10 +80,10 @@ public function get_query() {
/**
* Filter the $item_type to allow non-core item types.
*
* @param string $item_type Order item type.
* @param mixed $source The source that's passed down the GraphQL queries.
* @param array $args The inputArgs on the field.
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree.
* @param string $item_type Order item type.
* @param mixed $source The source that's passed down the GraphQL queries.
* @param array<string, mixed>|null $args The inputArgs on the field.
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree.
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo passed down the GraphQL tree.
*/
$type = apply_filters(
Expand Down Expand Up @@ -143,7 +143,7 @@ public function get_query() {

// Cache items for later.
foreach ( $items as $item ) {
$this->loader->prime(
$this->get_loader()->prime(
$item->get_id(),
new \WPGraphQL\WooCommerce\Model\Order_Item( $item, $this->source )
);
Expand Down
Loading
Loading