Skip to content

Commit

Permalink
WC_Term_Connection_Resolver class removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
kidunot89 committed Aug 6, 2020
1 parent c64c094 commit edf10a8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 118 deletions.
10 changes: 0 additions & 10 deletions includes/class-core-schema-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ public static function add_filters() {
add_filter( 'graphql_data_loaders', array( __CLASS__, 'graphql_data_loaders' ), 10, 2 );

// Adds connection resolutions for WooGraphQL type to WPGraphQL type connections.
add_filter(
'graphql_term_object_connection_query_args',
array(
'\WPGraphQL\WooCommerce\Data\Connection\WC_Term_Connection_Resolver',
'get_query_args',
),
10,
5
);

add_filter(
'graphql_comment_connection_query_args',
array(
Expand Down
42 changes: 25 additions & 17 deletions includes/connection/class-wc-terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public static function register_connections() {
'fromType' => $post_type_object->graphql_single_name,
'toType' => $tax_object->graphql_single_name,
'fromFieldName' => $tax_object->graphql_plural_name,
'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) {
$resolver = new TermObjectConnectionResolver( $source, $args, $context, $info, $tax_object->name );
$taxonomy = str_replace( ' ', '_', strtolower( $tax_object->labels->singular_name ) );
$resolver->set_query_arg( 'term_taxonomy_id', $source->{"{$taxonomy}_ids"} );

return $resolver->get_connection();
}
)
)
);
Expand All @@ -57,24 +64,35 @@ public static function register_connections() {
}
}

// From Coupons.
// From Coupons to ProductCategory connections.
$tax_object = get_taxonomy( 'product_cat' );
register_graphql_connection(
self::get_connection_config(
get_taxonomy( 'product_cat' ),
$tax_object,
array(
'fromType' => 'Coupon',
'toType' => 'ProductCategory',
'fromFieldName' => 'productCategories',
'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) {
$resolver = new TermObjectConnectionResolver( $source, $args, $context, $info, $tax_object->name );
$resolver->set_query_arg( 'term_taxonomy_id', $source->product_category_ids );

return $resolver->get_connection();
}
)
)
);
register_graphql_connection(
self::get_connection_config(
get_taxonomy( 'product_cat' ),
$tax_object,
array(
'fromType' => 'Coupon',
'toType' => 'ProductCategory',
'fromFieldName' => 'excludedProductCategories',
'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) {
$resolver = new TermObjectConnectionResolver( $source, $args, $context, $info, $tax_object->name );
$resolver->set_query_arg( 'term_taxonomy_id', $source->excluded_product_category_ids );

return $resolver->get_connection();
},
)
)
);
Expand All @@ -84,25 +102,15 @@ public static function register_connections() {
'fromType' => 'GlobalProductAttribute',
'toType' => 'TermNode',
'queryClass' => 'WP_Term_Query',
'resolveNode' => function( $id, array $args, AppContext $context ) {
return DataSource::resolve_term_object( $id, $context );
},
'fromFieldName' => 'terms',
'connectionArgs' => self::get_connection_args(),
'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) {
if ( ! $source->is_taxonomy() ) {
throw new UserError( __( 'Invalid product attribute', 'wp-graphql-woocommerce' ) );
}

$taxonomies = array( $source->get_name() );
$resolver = new TermObjectConnectionResolver(
$source,
$args,
$context,
$info,
$taxonomies
);

$resolver = new TermObjectConnectionResolver( $source, $args, $context, $info, $source->get_name() );
$resolver->set_query_arg( 'slug', $source->get_slugs() );
return $resolver->get_connection();
},
)
Expand Down
91 changes: 0 additions & 91 deletions includes/data/connection/class-wc-term-connection-resolver.php

This file was deleted.

0 comments on commit edf10a8

Please sign in to comment.