You are here

public function ResolveContextTest::testContextualArguments in GraphQL 8.3

Test manual context handling.

File

tests/src/Kernel/Extension/ResolveContextTest.php, line 66

Class

ResolveContextTest
Test contextual arguments in fields.

Namespace

Drupal\Tests\graphql\Kernel\Extension

Code

public function testContextualArguments() {
  $this
    ->mockType('test', [
    'name' => 'Test',
  ]);
  $this
    ->mockField('a', [
    'name' => 'a',
    'type' => 'Test',
    'arguments' => [
      'context' => 'String',
    ],
    'contextual_arguments' => [
      'context',
    ],
  ], function ($value, $args, ResolveContext $context, ResolveInfo $info) {
    (yield 'foo');
  });
  $this
    ->mockField('b', [
    'name' => 'b',
    'type' => 'String',
    'arguments' => [
      'context' => 'String',
    ],
    'contextual_arguments' => [
      'context',
    ],
    'parents' => [
      'Test',
    ],
  ], function ($value, $args, ResolveContext $context, ResolveInfo $info) {
    (yield $args['context']);
  });
  $this
    ->mockField('c', [
    'name' => 'c',
    'type' => 'String',
    'arguments' => [
      'context' => 'String',
    ],
    'contextual_arguments' => [
      'context',
    ],
  ], function ($value, $args, ResolveContext $context, ResolveInfo $info) {
    (yield $args['context']);
  });
  $query = <<<GQL
query {
  a (context: "test") {
    b
  }
  c
}
GQL;
  $this
    ->assertResults($query, [], [
    'a' => [
      'b' => 'test',
    ],
    'c' => NULL,
  ], $this
    ->defaultCacheMetaData());
}