You are here

private function IntrospectionTestTrait::indexByName in GraphQL 8.3

Recursively index all sequences by name.

@internal

Parameters

array $data: The input array.

1 call to IntrospectionTestTrait::indexByName()
IntrospectionTestTrait::introspect in tests/src/Traits/IntrospectionTestTrait.php
Retrieve a name-index schema to easy assert type system plugins.

File

tests/src/Traits/IntrospectionTestTrait.php, line 72

Class

IntrospectionTestTrait
Trait to retrieve a name-indexed schema to run assertions on it.

Namespace

Drupal\Tests\graphql\Traits

Code

private function indexByName(array &$data) {
  if (count(array_filter(array_keys($data), 'is_int')) == count($data)) {

    // This is a list, remap it.
    $data = array_combine(array_map(function ($key, $row) {
      return is_array($row) && isset($row['name']) ? $row['name'] : $key;
    }, array_keys($data), $data), $data);
  }
  foreach (array_keys($data) as $key) {
    if (is_array($data[$key])) {
      $this
        ->indexByName($data[$key]);
    }
  }
}