You are here

ConfigEntityTypeResolver.php in GraphQL 8

Same filename and directory in other branches
  1. 8.2 src/TypeResolver/ConfigEntityTypeResolver.php

File

src/TypeResolver/ConfigEntityTypeResolver.php
View source
<?php

namespace Drupal\graphql\TypeResolver;

use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface;
use Drupal\graphql\TypeResolverInterface;
use Fubhy\GraphQL\Language\Node;

/**
 * Resolves the schema for config entities.
 */
class ConfigEntityTypeResolver implements TypeResolverInterface {

  /**
   * The entity manager service.
   *
   * @var \Drupal\Core\Entity\EntityManagerInterface
   */
  protected $entityManager;

  /**
   * Constructs a ConfigEntityTypeResolver object.
   *
   * @param \Drupal\Core\Entity\EntityManagerInterface $entityManager
   *   The entity manager service.
   */
  public function __construct(EntityManagerInterface $entityManager) {
    $this->entityManager = $entityManager;
  }

  /**
   * {@inheritdoc}
   */
  public function applies($type) {
    if ($type instanceof EntityDataDefinitionInterface) {
      $entityTypeId = $type
        ->getEntityTypeId();
      $entityType = $this->entityManager
        ->getDefinition($entityTypeId);
      return $entityType
        ->isSubclassOf('\\Drupal\\Core\\Config\\Entity\\ConfigEntityInterface');
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function resolveRecursive($type) {

    // @todo We do not currently support config entities.
    return NULL;
  }

}

Classes

Namesort descending Description
ConfigEntityTypeResolver Resolves the schema for config entities.