public function ResultCacheTest::testVariables in GraphQL 8.3
Same name and namespace in other branches
- 8.4 tests/src/Kernel/Framework/ResultCacheTest.php \Drupal\Tests\graphql\Kernel\Framework\ResultCacheTest::testVariables()
Test if caching properly handles variabels.
File
- tests/
src/ Kernel/ Framework/ ResultCacheTest.php, line 100
Class
- ResultCacheTest
- Test query result caching.
Namespace
Drupal\Tests\graphql\Kernel\FrameworkCode
public function testVariables() {
$this
->mockField('root', [
'id' => 'root',
'name' => 'root',
'type' => 'String',
], NULL, function ($field) {
$field
->expects(static::exactly(2))
->method('resolveValues')
->willReturnCallback(function () {
(yield 'test');
});
});
// This result will be stored in the cache.
$this
->query('{ root }', [
'value' => 'a',
]);
// This will trigger a new evaluation since it passes different variables.
$this
->query('{ root }', [
'value' => 'b',
]);
// This should be served from cache.
$this
->query('{ root }', [
'value' => 'a',
]);
}