You are here

public function ResolverBuilderTest::testSimpleDefaultValue in GraphQL 8.4

@covers ::defaultValue

File

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

Class

ResolverBuilderTest
Tests that the resolver builder behaves correctly.

Namespace

Drupal\Tests\graphql\Kernel

Code

public function testSimpleDefaultValue() : void {
  $this
    ->mockResolver('Query', 'tree', [
    'name' => 'some tree',
    'id' => 5,
  ]);
  $this
    ->mockResolver('Tree', 'name', $this->builder
    ->defaultValue($this->builder
    ->fromValue(NULL), $this->builder
    ->fromValue('bar')));
  $this
    ->mockResolver('Tree', 'uri', $this->builder
    ->defaultValue($this->builder
    ->fromValue('baz'), $this->builder
    ->fromValue('bar')));
  $query = <<<GQL
      query {
        tree(id: 1) {
          name
          uri
        }
      }
GQL;
  $this
    ->assertResults($query, [], [
    'tree' => [
      'name' => 'bar',
      'uri' => 'baz',
    ],
  ]);
}