class RouteProvider in GraphQL 8.4
Provides Symfony routing information for each defined GraphQL server.
Hierarchy
- class \Drupal\graphql\RouteProvider
Expanded class hierarchy of RouteProvider
1 string reference to 'RouteProvider'
1 service uses RouteProvider
File
- src/
RouteProvider.php, line 12
Namespace
Drupal\graphqlView source
class RouteProvider {
/**
* The authentication collector service.
*
* @var \Drupal\Core\Authentication\AuthenticationCollectorInterface
*/
protected $authenticationCollector;
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* RouteProvider constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
* @param \Drupal\Core\Authentication\AuthenticationCollectorInterface $authenticationCollector
* The authentication collector service.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager, AuthenticationCollectorInterface $authenticationCollector) {
$this->authenticationCollector = $authenticationCollector;
$this->entityTypeManager = $entityTypeManager;
}
/**
* Collects routes for the server endpoints.
*/
public function routes() : array {
$storage = $this->entityTypeManager
->getStorage('graphql_server');
/** @var \Drupal\graphql\Entity\ServerInterface[] $servers */
$servers = $storage
->loadMultiple();
$routes = [];
// Allow all authentication providers by default.
$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;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteProvider:: |
protected | property | The authentication collector service. | |
RouteProvider:: |
protected | property | The entity type manager service. | |
RouteProvider:: |
public | function | Collects routes for the server endpoints. | |
RouteProvider:: |
public | function | RouteProvider constructor. |