View source  
  <?php
namespace Drupal\Tests\graphql\Kernel\Framework;
use Drupal\Tests\graphql\Kernel\GraphQLTestBase;
class SchemaCacheTest extends GraphQLTestBase {
  
  public function testCaching() {
    
    $this
      ->mockField('foo', [
      'id' => 'foo',
      'name' => 'foo',
      'type' => 'String',
    ], 'foo');
    
    $this
      ->introspect();
    
    $this
      ->mockField('bar', [
      'id' => 'bar',
      'name' => 'bar',
      'type' => 'String',
    ], 'bar');
    
    $schema = $this
      ->introspect();
    $this
      ->assertArrayNotHasKey('bar', $schema['types']['Query']['fields'], 'Schema has not been cached.');
  }
  
  public function testCachingWithInvalidation() {
    
    $this
      ->mockField('foo', [
      'id' => 'foo',
      'name' => 'foo',
      'type' => 'String',
    ], 'foo');
    
    $this
      ->introspect();
    
    $this
      ->mockField('bar', [
      'id' => 'bar',
      'name' => 'bar',
      'type' => 'String',
    ], 'bar');
    
    $schema = $this
      ->introspect();
    $this
      ->assertArrayNotHasKey('bar', $schema['types']['Query']['fields'], 'Schema has not been cached.');
    $this->container
      ->get('cache_tags.invalidator')
      ->invalidateTags([
      'graphql',
    ]);
    
    $schema = $this
      ->introspect();
    $this
      ->assertArrayHasKey('bar', $schema['types']['Query']['fields'], 'Schema does not contain the new field.');
  }
}