You are here

class QueryRoutes in GraphQL 8.3

Registers graphql query routes for all schemas.

Hierarchy

  • class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of QueryRoutes

1 string reference to 'QueryRoutes'
graphql.services.yml in ./graphql.services.yml
graphql.services.yml
1 service uses QueryRoutes
graphql.query_routes in ./graphql.services.yml
Drupal\graphql\Routing\QueryRoutes

File

src/Routing/QueryRoutes.php, line 14

Namespace

Drupal\graphql\Routing
View source
class QueryRoutes extends RouteSubscriberBase {

  /**
   * The graphql schema plugin manager.
   *
   * @var \Drupal\graphql\Plugin\SchemaPluginManager
   */
  protected $schemaManager;

  /**
   * The authentication collector.
   *
   * @var \Drupal\Core\Authentication\AuthenticationCollectorInterface
   */
  protected $authenticationCollector;

  /**
   * QueryRoutes constructor.
   *
   * @param \Drupal\graphql\Plugin\SchemaPluginManager $schemaManager
   *   The graphql schema plugin manager.
   * @param \Drupal\Core\Authentication\AuthenticationCollectorInterface $authenticationCollector
   *   The authentication collector.
   */
  public function __construct(SchemaPluginManager $schemaManager, AuthenticationCollectorInterface $authenticationCollector) {
    $this->schemaManager = $schemaManager;
    $this->authenticationCollector = $authenticationCollector;
  }

  /**
   * Alters existing routes for a specific collection.
   *
   * @param \Symfony\Component\Routing\RouteCollection $collection
   *   The route collection for adding routes.
   */
  protected function alterRoutes(RouteCollection $collection) {
    $routes = new RouteCollection();
    $providers = $this->authenticationCollector
      ->getSortedProviders();
    $providerIds = array_keys($providers);
    foreach ($this->schemaManager
      ->getDefinitions() as $key => $definition) {
      $routes
        ->add("graphql.query.{$key}", new Route($definition['path'], [
        'schema' => $key,
        '_graphql' => TRUE,
        '_controller' => '\\Drupal\\graphql\\Controller\\RequestController::handleRequest',
        '_disable_route_normalizer' => 'TRUE',
      ], [
        '_graphql_query_access' => 'TRUE',
      ], [
        '_auth' => $providerIds,
      ]));
    }
    $collection
      ->addCollection($routes);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
QueryRoutes::$authenticationCollector protected property The authentication collector.
QueryRoutes::$schemaManager protected property The graphql schema plugin manager.
QueryRoutes::alterRoutes protected function Alters existing routes for a specific collection. Overrides RouteSubscriberBase::alterRoutes
QueryRoutes::__construct public function QueryRoutes constructor.
RouteSubscriberBase::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. 5
RouteSubscriberBase::onAlterRoutes public function Delegates the route altering to self::alterRoutes(). 1