Code Duplication    Length = 44-46 lines in 4 locations

src/Routing/ExplorerRoutes.php 1 location

@@ 13-56 (lines=44) @@
10
/**
11
 * Registers graphql explorer routes for all schemas.
12
 */
13
class ExplorerRoutes extends RouteSubscriberBase {
14
15
  /**
16
   * The graphql schema plugin manager.
17
   *
18
   * @var \Drupal\graphql\Plugin\GraphQL\SchemaPluginManager
19
   */
20
  protected $schemaManager;
21
22
  /**
23
   * Constructs a QueryRoutes object.
24
   *
25
   * @param \Drupal\graphql\Plugin\GraphQL\SchemaPluginManager $schemaManager
26
   *   The graphql schema plugin manager.
27
   */
28
  public function __construct(SchemaPluginManager $schemaManager) {
29
    $this->schemaManager = $schemaManager;
30
  }
31
32
  /**
33
   * Alters existing routes for a specific collection.
34
   *
35
   * @param \Symfony\Component\Routing\RouteCollection $collection
36
   *   The route collection for adding routes.
37
   */
38
  protected function alterRoutes(RouteCollection $collection) {
39
    $routes = new RouteCollection();
40
41
    foreach ($this->schemaManager->getDefinitions() as $key => $definition) {
42
      $routes->add("graphql.explorer.$key", new Route("{$definition['path']}/explorer", [
43
        'schema' => $key,
44
        '_controller' => '\Drupal\graphql\Controller\ExplorerController::viewExplorer',
45
        '_title' => 'GraphiQL',
46
      ], [
47
        '_permission' => 'use graphql explorer',
48
      ], [
49
        '_admin_route' => 'TRUE',
50
      ]));
51
    }
52
53
    $collection->addCollection($routes);
54
  }
55
56
}
57

src/Routing/QueryRoutes.php 1 location

@@ 13-56 (lines=44) @@
10
/**
11
 * Registers graphql query routes for all schemas.
12
 */
13
class QueryRoutes extends RouteSubscriberBase {
14
15
  /**
16
   * The graphql schema plugin manager.
17
   *
18
   * @var \Drupal\graphql\Plugin\GraphQL\SchemaPluginManager
19
   */
20
  protected $schemaManager;
21
22
  /**
23
   * Constructs a QueryRoutes object.
24
   *
25
   * @param \Drupal\graphql\Plugin\GraphQL\SchemaPluginManager $schemaManager
26
   *   The graphql schema plugin manager.
27
   */
28
  public function __construct(SchemaPluginManager $schemaManager) {
29
    $this->schemaManager = $schemaManager;
30
  }
31
32
  /**
33
   * Alters existing routes for a specific collection.
34
   *
35
   * @param \Symfony\Component\Routing\RouteCollection $collection
36
   *   The route collection for adding routes.
37
   */
38
  protected function alterRoutes(RouteCollection $collection) {
39
    $routes = new RouteCollection();
40
41
    foreach ($this->schemaManager->getDefinitions() as $key => $definition) {
42
      $routes->add("graphql.query.$key", new Route($definition['path'], [
43
        'schema' => $key,
44
        '_graphql' => [
45
          'single' => '\Drupal\graphql\Controller\RequestController::handleRequest',
46
          'multiple' => '\Drupal\graphql\Controller\RequestController::handleBatchRequest',
47
        ],
48
      ], [
49
        '_graphql_query_access' => 'TRUE',
50
      ]));
51
    }
52
53
    $collection->addCollection($routes);
54
  }
55
56
}
57

src/Routing/VoyagerRoutes.php 1 location

@@ 13-56 (lines=44) @@
10
/**
11
 * Registers graphql voyager routes for all schemas.
12
 */
13
class VoyagerRoutes extends RouteSubscriberBase {
14
15
  /**
16
   * The graphql schema plugin manager.
17
   *
18
   * @var \Drupal\graphql\Plugin\GraphQL\SchemaPluginManager
19
   */
20
  protected $schemaManager;
21
22
  /**
23
   * Constructs a QueryRoutes object.
24
   *
25
   * @param \Drupal\graphql\Plugin\GraphQL\SchemaPluginManager $schemaManager
26
   *   The graphql schema plugin manager.
27
   */
28
  public function __construct(SchemaPluginManager $schemaManager) {
29
    $this->schemaManager = $schemaManager;
30
  }
31
32
  /**
33
   * Alters existing routes for a specific collection.
34
   *
35
   * @param \Symfony\Component\Routing\RouteCollection $collection
36
   *   The route collection for adding routes.
37
   */
38
  protected function alterRoutes(RouteCollection $collection) {
39
    $routes = new RouteCollection();
40
41
    foreach ($this->schemaManager->getDefinitions() as $key => $definition) {
42
      $routes->add("graphql.voyager.$key", new Route("{$definition['path']}/voyager", [
43
        'schema' => $key,
44
        '_controller' => '\Drupal\graphql\Controller\VoyagerController::viewVoyager',
45
        '_title' => 'GraphQL Voyager',
46
      ], [
47
        '_permission' => 'use graphql voyager',
48
      ], [
49
        '_admin_route' => 'TRUE',
50
      ]));
51
    }
52
53
    $collection->addCollection($routes);
54
  }
55
56
}
57

src/Routing/ConfigurationRoutes.php 1 location

@@ 13-58 (lines=46) @@
10
/**
11
 * Registers routes for all configurable schemas.
12
 */
13
class ConfigurationRoutes extends RouteSubscriberBase {
14
15
  /**
16
   * The graphql schema plugin manager.
17
   *
18
   * @var \Drupal\graphql\Plugin\GraphQL\SchemaPluginManager
19
   */
20
  protected $schemaManager;
21
22
  /**
23
   * Constructs a QueryRoutes object.
24
   *
25
   * @param \Drupal\graphql\Plugin\GraphQL\SchemaPluginManager $schemaManager
26
   *   The graphql schema plugin manager.
27
   */
28
  public function __construct(SchemaPluginManager $schemaManager) {
29
    $this->schemaManager = $schemaManager;
30
  }
31
32
  /**
33
   * Alters existing routes for a specific collection.
34
   *
35
   * @param \Symfony\Component\Routing\RouteCollection $collection
36
   *   The route collection for adding routes.
37
   */
38
  protected function alterRoutes(RouteCollection $collection) {
39
    $routes = new RouteCollection();
40
41
    foreach ($this->schemaManager->getDefinitions() as $key => $definition) {
42
      if (empty($definition['uses_plugins'])) {
43
        continue;
44
      }
45
46
      $routes->add("graphql.configuration.$key", new Route("{$definition['path']}/configure", [
47
        'schema' => $key,
48
        '_controller' => '\Drupal\graphql\Controller\ConfigurationController::configurationOverview',
49
        '_title' => 'Configuration',
50
      ], [
51
        '_admin_route' => 'TRUE',
52
      ]));
53
    }
54
55
    $collection->addCollection($routes);
56
  }
57
58
}
59