public function ResolveContextTest::testResolveContext in GraphQL 8.3
Test manual context handling.
File
- tests/
src/ Kernel/ Extension/ ResolveContextTest.php, line 19
Class
- ResolveContextTest
- Test contextual arguments in fields.
Namespace
Drupal\Tests\graphql\Kernel\ExtensionCode
public function testResolveContext() {
$this
->mockType('test', [
'name' => 'Test',
]);
$this
->mockField('a', [
'name' => 'a',
'type' => 'Test',
], function ($value, $args, ResolveContext $context, ResolveInfo $info) {
$context
->setContext('context', 'test', $info);
(yield 'foo');
});
$this
->mockField('b', [
'name' => 'b',
'type' => 'String',
'parents' => [
'Test',
],
], function ($value, $args, ResolveContext $context, ResolveInfo $info) {
(yield $context
->getContext('context', $info));
});
$this
->mockField('c', [
'name' => 'c',
'type' => 'String',
], function ($value, $args, ResolveContext $context, ResolveInfo $info) {
(yield $context
->getContext('context', $info));
});
$query = <<<GQL
query {
a {
b
}
c
}
GQL;
$this
->assertResults($query, [], [
'a' => [
'b' => 'test',
],
'c' => NULL,
], $this
->defaultCacheMetaData());
}