Repository: wp-graphql/wp-graphql (language: php)

Issue:
connectedTerms of taxonomies nodes return all terms for all taxonomies
### Description

When I try to get the `connectedTerms` for taxonomies nodes, I got all terms, env the terms for other taxonomies
 
![image](https://github.com/user-attachments/assets/891b2b7b-d610-4655-8f75-05dc231eedb8)


### Steps to reproduce

1. Go on "category" and create some random categories
2. Go on "tag" and create some random tags
3. Go on GraphQL and query all connectedTerms for taxonomies nodes
``` graphql
{
  taxonomies(first: 100) {
    nodes {
      name
      connectedTerms {
        nodes {
          uri
          taxonomyName
        }
      }
    }
  }
}
```

### Additional context

_No response_

### WPGraphQL Version

1.28.1

### WordPress Version

6.6.1

### PHP Version

8.1.23

### Additional environment details

| Plugins                     | Version |
|-----------------------------|---------|
| Add WPGraphQL SEO           | 4.22.5  |
| WPGraphQL Content Blocks    | 4.0.1   |
| WPGraphQL for ACF           | 2.4.1   |
| WPGraphQL Offset Pagination | 0.2.0   |
| JSON Basic Authentication   | 0.1     |

* Tested with all plugins deactivated and default WordPress theme

### Please confirm that you have searched existing issues in the repo.

- [X] Yes

### Please confirm that you have disabled ALL plugins except for WPGraphQL.

- [X] Yes
- [ ] My issue is with compatibility with a specific WordPress plugin, and I have listed all my installed plugins (and version info) above.


Discussion / hints:
Hey @MKlblangenois thanks for the report! We were able to reproduce this and will be looking into a solution.

Fix patch:
diff --git a/src/Data/Connection/TermObjectConnectionResolver.php b/src/Data/Connection/TermObjectConnectionResolver.php
index 397de4302..9f0d7faea 100644
--- a/src/Data/Connection/TermObjectConnectionResolver.php
+++ b/src/Data/Connection/TermObjectConnectionResolver.php
@@ -35,7 +35,12 @@ public function __construct( $source, array $args, AppContext $context, ResolveI
 	 */
 	protected function prepare_query_args( array $args ): array {
 		$all_taxonomies = \WPGraphQL::get_allowed_taxonomies();
-		$taxonomy       = ! empty( $this->taxonomy ) && in_array( $this->taxonomy, $all_taxonomies, true ) ? [ $this->taxonomy ] : $all_taxonomies;
+
+		if ( ! is_array( $this->taxonomy ) ) {
+			$taxonomy = ! empty( $this->taxonomy ) && in_array( $this->taxonomy, $all_taxonomies, true ) ? [ $this->taxonomy ] : $all_taxonomies;
+		} else {
+			$taxonomy = $this->taxonomy;
+		}
 
 		if ( ! empty( $args['where']['taxonomies'] ) ) {
 			/**


Test patch:
diff --git a/tests/wpunit/TermObjectConnectionQueriesTest.php b/tests/wpunit/TermObjectConnectionQueriesTest.php
index 7a672db10..b2f5c2800 100644
--- a/tests/wpunit/TermObjectConnectionQueriesTest.php
+++ b/tests/wpunit/TermObjectConnectionQueriesTest.php
@@ -109,6 +109,62 @@ public function getQuery() {
 		';
 	}
 
+	public function testConnectedTermsConnectionReturnsTermNodesOfExpectedTaxonomies() {
+		$term_one_id = self::factory()->term->create(
+			[
+				'taxonomy' => 'category',
+				'name'     => 'Term One',
+			]
+		);
+
+		$term_two_id = self::factory()->term->create(
+			[
+				'taxonomy' => 'post_tag',
+				'name'     => 'Term Two',
+			]
+		);
+
+		$query = '
+		query GetConnectedTerms {
+			taxonomies {
+				nodes {
+					name
+					connectedTerms {
+						nodes {
+							__typename
+							databaseId
+							name
+							uri
+						}
+					}
+				}
+			} 
+		}
+		';
+
+		$actual = $this->graphql([
+			'query' => $query
+		]);
+
+		// codecept_debug( [ '$actual' => $actual ]);
+		$this->assertArrayNotHasKey( 'errors', $actual );
+
+		// map over the connected terms nodes and assert that all of them are category
+		$connected_categories = $actual['data']['taxonomies']['nodes'][0]['connectedTerms']['nodes'];
+		foreach ( $connected_categories as $connected_category ) {
+			$this->assertEquals( 'Category', $connected_category['__typename'] );
+		}
+
+		// map over the connected terms nodes and assert that all of them are tags
+		$connected_tags = $actual['data']['taxonomies']['nodes'][1]['connectedTerms']['nodes'];
+		foreach ( $connected_tags as $connected_tag ) {
+			$this->assertEquals( 'Tag', $connected_tag['__typename'] );			
+		}
+
+		wp_delete_term( $term_one_id, 'category' );
+		wp_delete_term( $term_two_id, 'post_tag' );
+	}
+
 	public function testForwardPagination() {
 		$query    = $this->getQuery();
 		$wp_query = new WP_Term_Query();
@@ -945,4 +1001,5 @@ public function testPaginateTermsWithDuplicateNamesAndOrderbyName() {
 
 		wp_delete_term( $parent_category, 'category' );
 	}
+
 }