class QueryRoutes in GraphQL 8.3
Registers graphql query routes for all schemas.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\graphql\Routing\QueryRoutes
Expanded class hierarchy of QueryRoutes
1 string reference to 'QueryRoutes'
1 service uses QueryRoutes
File
- src/
Routing/ QueryRoutes.php, line 14
Namespace
Drupal\graphql\RoutingView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
QueryRoutes:: |
protected | property | The authentication collector. | |
QueryRoutes:: |
protected | property | The graphql schema plugin manager. | |
QueryRoutes:: |
protected | function |
Alters existing routes for a specific collection. Overrides RouteSubscriberBase:: |
|
QueryRoutes:: |
public | function | QueryRoutes constructor. | |
RouteSubscriberBase:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | 5 |
RouteSubscriberBase:: |
public | function | Delegates the route altering to self::alterRoutes(). | 1 |