You are here

public function Seek::resolve in GraphQL 8.4

Resolver.

Parameters

array $input: The input array.

int $position: The position to seek.

Return value

mixed The element at the specified position.

File

src/Plugin/GraphQL/DataProducer/Utility/Seek.php, line 41

Class

Seek
Return an item from a list at a specified position.

Namespace

Drupal\graphql\Plugin\GraphQL\DataProducer\Utility

Code

public function resolve(array $input, $position) {
  $array_object = new \ArrayObject($input);
  $iterator = $array_object
    ->getIterator();
  try {
    $iterator
      ->seek($position);
  } catch (\OutOfBoundsException $e) {
    return NULL;
  }
  return $iterator
    ->current();
}