You are here

public function ResolverBuilderTest::testFromPath in GraphQL 8.4

@covers ::fromPath

File

tests/src/Kernel/ResolverBuilderTest.php, line 130

Class

ResolverBuilderTest
Tests that the resolver builder behaves correctly.

Namespace

Drupal\Tests\graphql\Kernel

Code

public function testFromPath() : void {
  $manager = $this->container
    ->get('typed_data_manager');
  $tree_definition = $manager
    ->createDataDefinition('tree');

  /** @var \Drupal\graphql_resolver_builder_test\Plugin\DataType\Tree $right */
  $right = $manager
    ->create($tree_definition);
  $right
    ->set('value', 'Front page');

  /** @var \Drupal\graphql_resolver_builder_test\Plugin\DataType\Tree $tree */
  $tree = $manager
    ->create($tree_definition);
  $tree
    ->set('left', [
    'value' => '<front>',
    'right' => $right,
  ]);
  $this
    ->mockResolver('Query', 'tree', $this->builder
    ->fromValue($tree));
  $this
    ->mockResolver('Tree', 'uri', $this->builder
    ->fromPath('tree', 'left.value'));
  $query = <<<GQL
      query {
        tree {
          uri
        }
      }
GQL;
  $this
    ->assertResults($query, [], [
    'tree' => [
      'uri' => '<front>',
    ],
  ]);
}