You are here

public function ResolverBuilderTest::testDeferredDefaultValue in GraphQL 8.4

@covers ::defaultValue

File

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

Class

ResolverBuilderTest
Tests that the resolver builder behaves correctly.

Namespace

Drupal\Tests\graphql\Kernel

Code

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