Connect terms to their source

Rather than assume this only runs on `$attributes`, we need to connect the $source to it's given `$tax_object` that is passed instead.
This commit is contained in:
Jacob Arriola
2020-10-21 11:33:13 -07:00
committed by GitHub
parent 697422ee2f
commit 3fc6ebeeb4
+6 -3
View File
@@ -49,9 +49,12 @@ class WC_Terms extends TermObjects {
'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 );
$options = $source->attributes[ $tax_object->name ]['options'];
$resolver->set_query_arg( 'term_taxonomy_id', ! empty( $options ) ? $options : array( '0' ) );
$resolver = new TermObjectConnectionResolver( $source, $args, $context, $info, $tax_object->name );
// Get the term ids that are associated with this $source
$terms = wp_list_pluck( get_the_terms( $source->ID, $tax_object->name ), 'term_id' );
$resolver->set_query_arg( 'term_taxonomy_id', ! empty( $terms ) ? $terms : array( '0' ) );
return $resolver->get_connection();
}