RouteProvider.php in GraphQL 8.4
File
src/RouteProvider.php
View source
<?php
namespace Drupal\graphql;
use Drupal\Core\Authentication\AuthenticationCollectorInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\Routing\Route;
class RouteProvider {
protected $authenticationCollector;
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entityTypeManager, AuthenticationCollectorInterface $authenticationCollector) {
$this->authenticationCollector = $authenticationCollector;
$this->entityTypeManager = $entityTypeManager;
}
public function routes() : array {
$storage = $this->entityTypeManager
->getStorage('graphql_server');
$servers = $storage
->loadMultiple();
$routes = [];
$auth = array_keys($this->authenticationCollector
->getSortedProviders());
foreach ($servers as $id => $server) {
$path = $server
->get('endpoint');
$routes["graphql.query.{$id}"] = (new Route($path))
->addDefaults([
'graphql_server' => $id,
'_graphql' => TRUE,
'_controller' => '\\Drupal\\graphql\\Controller\\RequestController::handleRequest',
'_disable_route_normalizer' => TRUE,
])
->addRequirements([
'_graphql_query_access' => 'graphql_server:{graphql_server}',
'_format' => 'json',
])
->addOptions([
'_auth' => $auth,
'no_cache' => TRUE,
'default_url_options' => [
'path_processing' => FALSE,
],
'parameters' => [
'graphql_server' => [
'type' => 'entity:graphql_server',
],
],
]);
}
return $routes;
}
}
Classes
Name |
Description |
RouteProvider |
Provides Symfony routing information for each defined GraphQL server. |