You are here

public function ResolverBuilderTest::testParentCond in GraphQL 8.4

@covers ::cond

File

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

Class

ResolverBuilderTest
Tests that the resolver builder behaves correctly.

Namespace

Drupal\Tests\graphql\Kernel

Code

public function testParentCond() : void {
  $this
    ->mockResolver('Query', 'tree', [
    'name' => 'some tree',
    'id' => 5,
  ]);
  $this
    ->mockResolver('Tree', 'name', $this->builder
    ->cond([
    [
      $this->builder
        ->fromValue(FALSE),
      $this->builder
        ->fromValue('This should not be in the result.'),
    ],
    [
      $this->builder
        ->fromParent(),
      $this->builder
        ->fromValue('But this should.'),
    ],
    [
      $this->builder
        ->fromValue(TRUE),
      $this->builder
        ->fromValue('And this not, event though its true.'),
    ],
  ]));
  $query = <<<GQL
      query {
        tree {
          name
        }
      }
GQL;
  $this
    ->assertResults($query, [], [
    'tree' => [
      'name' => 'But this should.',
    ],
  ]);
}