public function RouteProvider::routes in GraphQL 8.4
Collects routes for the server endpoints.
File
- src/
RouteProvider.php, line 44
Class
- RouteProvider
- Provides Symfony routing information for each defined GraphQL server.
Namespace
Drupal\graphqlCode
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;
}