QueryRoutes.php in GraphQL 8.3
File
src/Routing/QueryRoutes.php
View source
<?php
namespace Drupal\graphql\Routing;
use Drupal\Core\Authentication\AuthenticationCollectorInterface;
use Drupal\Core\Routing\RouteSubscriberBase;
use Drupal\graphql\Plugin\SchemaPluginManager;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class QueryRoutes extends RouteSubscriberBase {
protected $schemaManager;
protected $authenticationCollector;
public function __construct(SchemaPluginManager $schemaManager, AuthenticationCollectorInterface $authenticationCollector) {
$this->schemaManager = $schemaManager;
$this->authenticationCollector = $authenticationCollector;
}
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);
}
}
Classes
Name |
Description |
QueryRoutes |
Registers graphql query routes for all schemas. |