You are here

protected function ExplorerRoutes::alterRoutes in GraphQL 8.3

Alters existing routes for a specific collection.

Parameters

\Symfony\Component\Routing\RouteCollection $collection: The route collection for adding routes.

Overrides RouteSubscriberBase::alterRoutes

File

src/Routing/ExplorerRoutes.php, line 38

Class

ExplorerRoutes
Registers graphql explorer routes for all schemas.

Namespace

Drupal\graphql\Routing

Code

protected function alterRoutes(RouteCollection $collection) {
  $routes = new RouteCollection();
  foreach ($this->schemaManager
    ->getDefinitions() as $key => $definition) {
    $routes
      ->add("graphql.explorer.{$key}", new Route("{$definition['path']}/explorer", [
      'schema' => $key,
      '_controller' => '\\Drupal\\graphql\\Controller\\ExplorerController::viewExplorer',
      '_title' => 'GraphiQL',
    ], [
      '_permission' => 'use graphql explorer',
    ], [
      '_admin_route' => 'TRUE',
    ]));
  }
  $collection
    ->addCollection($routes);
}