You are here

public function ResultCacheTest::testPersistedQuery in GraphQL 8.3

Test persisted query handling.

Ensure caching properly handles different query map versions of the same query.

File

tests/src/Kernel/Framework/ResultCacheTest.php, line 220

Class

ResultCacheTest
Test query result caching.

Namespace

Drupal\Tests\graphql\Kernel\Framework

Code

public function testPersistedQuery() {
  $queryProvider = $this
    ->prophesize(QueryProviderInterface::class);
  $this->container
    ->set('graphql.query_provider', $queryProvider
    ->reveal());
  $queryProvider
    ->getQuery('query:a', Argument::any())
    ->willReturn('{ a }');
  $queryProvider
    ->getQuery('query:b', Argument::any())
    ->willReturn('{ b }');
  $this
    ->mockField('a', [
    'id' => 'a',
    'name' => 'a',
    'type' => 'String',
  ], NULL, function ($field) {
    $field
      ->expects(static::exactly(1))
      ->method('resolveValues')
      ->willReturnCallback(function () {
      (yield 'a');
    });
  });
  $this
    ->mockField('b', [
    'id' => 'b',
    'name' => 'b',
    'type' => 'String',
  ], NULL, function ($field) {
    $field
      ->expects(static::exactly(2))
      ->method('resolveValues')
      ->willReturnCallback(function () {
      (yield 'b');
    });
  });
  $this
    ->persistedQuery('query:a');
  $this
    ->persistedQuery('query:b');
  $this
    ->persistedQuery('query:a');
  $this
    ->persistedQuery('query:b', [
    'value' => 'test',
  ]);
}