You are here

public function ResolverBuilderTest::testFromContext in GraphQL 8.4

@covers ::context @covers ::fromContext

File

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

Class

ResolverBuilderTest
Tests that the resolver builder behaves correctly.

Namespace

Drupal\Tests\graphql\Kernel

Code

public function testFromContext() : void {
  $this
    ->mockResolver('Query', 'tree', $this->builder
    ->fromValue('some value'));
  $this
    ->mockResolver('Tree', 'context', $this->builder
    ->compose($this->builder
    ->context('my context', $this->builder
    ->fromValue('my context value')), $this->builder
    ->fromValue('some language value')));
  $this
    ->mockResolver('Context', 'myContext', $this->builder
    ->fromContext('my context'));
  $query = <<<GQL
      query {
        tree {
          context {
            myContext
          }
        }
      }
GQL;
  $this
    ->assertResults($query, [], [
    'tree' => [
      'context' => [
        'myContext' => 'my context value',
      ],
    ],
  ]);
}