You are here

protected function QueryRoutes::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/QueryRoutes.php, line 49

Class

QueryRoutes
Registers graphql query routes for all schemas.

Namespace

Drupal\graphql\Routing

Code

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);
}