wp-graphql-woocommerce
wp-graphql-woocommerce copied to clipboard
$source is getting null on graphql_product_connection_query_args
Describe the bug I am trying to use graphql_product_connection_query_args filter like this -
add_filter( 'graphql_product_connection_query_args', function ( $query_args, $source, $args, $context, $info ) {
if ( 'auction' !== $source->type ) {
return $query_args;
}
$query_args['auction_arhive'] = true;
$query_args['show_past_auctions'] = true;
return $query_args;
}, 10, 5 );
Using this code, $source is getting null. it should be a product object if I am not wrong.
Please suggest if I am missing something. Thanks
Plugin Versions
**WooGraphQL Version: 0.7.0 **WPGraphQL Version 1.1.3 **WordPress Version: 5.6.1 **WooCommerce Version: 4.9.2
@akshaykatale99 The $source is the current node of which that the products are supposed to be branch to not the product objects themselves.
The graphql_product_connection_query_args is meant for altering query arguments used by all product connection queries and it's use is sparingly recommended. Instead try registering a new connection. See the Coupon to Products connection registration definitions here as an example
So what is it you are trying to achieve
Hi, thanks for the response. I have added the custom product type. followed this nice blog post https://jacobarriola.com/post/graphql-woocommerce-connection-product-bundles
This is the snippet from this blog post.
add_filter( 'graphql_product_connection_query_args', function ( $query_args, $source, $args, $context, $info ) {
// Bail if this isn't a bundle. This filter runs on all product types
if ( 'bundle' !== $source->type ) {
return $query_args;
}
$query_args['post__in'] = [ 123, 456 ];
return $query_args;
}, 10, 5 );
The thing is, i am able to add the custom product type. when i query to get list of products then product with auction product type is not listing.

Thanks
@akshaykatale99 Have you tried this query?
query {
products( where: { type: AUCTION } ) {
nodes {
... on AuctionProduct {
name
type
}
}
}
}
@kidunot89 Yes I have tried this query and able to get auction products in products query. but the thing is, when I add this product to the cart then this type of product is not fetching on cart query.
:thinking: Oh yea, the cart item types are restricted to Variable and Simple by default.
Wait, no it's not. I was wrong :sweat_smile:
without the following condition in graphql_product_connection_query_args, I am not able to get the auction products using where: { type: AUCTION }.
if(isset($query_args['graphql_args']['where']['type']) && $query_args['graphql_args']['where']['type'] == 'auction'){
$query_args['auction_arhive'] = true;
$query_args['show_past_auctions'] = true;
}
I have added this condition as a workaround but this not working on the cart. if I add these two query args without condition then I am able to get the product on the cart also but this filter is applying to all product types.
@akshaykatale99 did you add your new type to the product types enum? I wonder if that's the issue. See https://jacobarriola.com/post/woocommerce-graphql-product-bundles#step-four-add-bundle-to-the-product-types-enum
@jacobarriola Yes i have added new product type to the product types enum.
add_filter( 'graphql_product_types_enum_values', function ( $values ) {
$values['AUCTION'] = [
'value' => 'auction',
'description' => 'A auction product',
];
return $values;
} );
@akshaykatale99 does using the following without the conditional statement resolve the issues with cart items without breaking the existing products connection queries?
$query_args['auction_archive'] = true;
$query_args['show_past_auctions'] = true;
@akshaykatale99 does using the following without the conditional statement resolve the issues with cart items without breaking the existing products connection queries?
$query_args['auction_archive'] = true; $query_args['show_past_auctions'] = true;
@kidunot89 Yes it is working without a conditional statement. but it's affecting some other queries for eg. if I apply auction_archive without condition then some variable products variations are getting null