You are here

class ExplorerRoutes in GraphQL 8.3

Registers graphql explorer routes for all schemas.

Hierarchy

Expanded class hierarchy of ExplorerRoutes

1 string reference to 'ExplorerRoutes'
graphql.services.yml in ./graphql.services.yml
graphql.services.yml
1 service uses ExplorerRoutes
graphql.graphiql.explorer_routes in ./graphql.services.yml
Drupal\graphql\Routing\ExplorerRoutes

File

src/Routing/ExplorerRoutes.php, line 13

Namespace

Drupal\graphql\Routing
View source
class ExplorerRoutes extends RouteSubscriberBase {

  /**
   * The graphql schema plugin manager.
   *
   * @var \Drupal\graphql\Plugin\SchemaPluginManager
   */
  protected $schemaManager;

  /**
   * ExplorerRoutes constructor.
   *
   * @param \Drupal\graphql\Plugin\SchemaPluginManager $schemaManager
   *   The graphql schema plugin manager.
   */
  public function __construct(SchemaPluginManager $schemaManager) {
    $this->schemaManager = $schemaManager;
  }

  /**
   * 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();
    foreach ($this->schemaManager
      ->getDefinitions() as $key => $definition) {
      $routes
        ->add("graphql.explorer.{$key}", new Route("{$definition['path']}/explorer", [
        'schema' => $key,
        '_controller' => '\\Drupal\\graphql\\Controller\\ExplorerController::viewExplorer',
        '_title' => 'GraphiQL',
      ], [
        '_permission' => 'use graphql explorer',
      ], [
        '_admin_route' => 'TRUE',
      ]));
    }
    $collection
      ->addCollection($routes);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExplorerRoutes::$schemaManager protected property The graphql schema plugin manager.
ExplorerRoutes::alterRoutes protected function Alters existing routes for a specific collection. Overrides RouteSubscriberBase::alterRoutes
ExplorerRoutes::__construct public function ExplorerRoutes constructor.
RouteSubscriberBase::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. 5
RouteSubscriberBase::onAlterRoutes public function Delegates the route altering to self::alterRoutes(). 1