Skip to content

Commit f6babda

Browse files
committed
dev: refactor AbstractConnectionResolver::get_ids() to ::prepare_ids()
1 parent b266d3e commit f6babda

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/Data/Connection/AbstractConnectionResolver.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ abstract class AbstractConnectionResolver {
119119
/**
120120
* The IDs returned from the query.
121121
*
122-
* @var int[]|string[]
122+
* @var int[]|string[]|null
123123
*/
124124
protected $ids;
125125

@@ -543,9 +543,11 @@ public function get_should_execute(): bool {
543543
* @return int[]|string[]
544544
*/
545545
public function get_ids() {
546-
$ids = $this->get_ids_from_query();
546+
if ( ! isset( $this->ids ) ) {
547+
$this->ids = $this->prepare_ids();
548+
}
547549

548-
return $this->apply_cursors_to_ids( $ids );
550+
return $this->ids;
549551
}
550552

551553
/**
@@ -761,6 +763,7 @@ public function get_connection() {
761763
return new Deferred(
762764
function () {
763765
if ( ! empty( $this->ids ) ) {
766+
// Load the ids.
764767
$this->get_loader()->load_many( $this->ids );
765768
}
766769

@@ -866,6 +869,8 @@ public function execute_and_get_ids() {
866869
/**
867870
* Filter the connection IDs
868871
*
872+
* @todo We filter the IDs here for b/c. Once that is not a concern, we should relocate this filter to ::get_ids().
873+
*
869874
* @param int[]|string[] $ids Array of IDs this connection will be resolving
870875
* @param \WPGraphQL\Data\Connection\AbstractConnectionResolver $connection_resolver Instance of the Connection Resolver
871876
*/
@@ -967,6 +972,19 @@ protected function prepare_nodes(): array {
967972
return $nodes;
968973
}
969974

975+
/**
976+
* Prepares the IDs for the connection.
977+
*
978+
* @used-by self::get_ids()
979+
*
980+
* @return int[]|string[]
981+
*/
982+
protected function prepare_ids(): array {
983+
$ids = $this->get_ids_from_query();
984+
985+
return $this->apply_cursors_to_ids( $ids );
986+
}
987+
970988
/**
971989
* Gets the IDs for the currently-paginated slice of nodes.
972990
*

0 commit comments

Comments
 (0)