You are here

public function ExplorerController::viewExplorer in GraphQL 8.3

Same name and namespace in other branches
  1. 8.4 src/Controller/ExplorerController.php \Drupal\graphql\Controller\ExplorerController::viewExplorer()
  2. 8 src/Controller/ExplorerController.php \Drupal\graphql\Controller\ExplorerController::viewExplorer()
  3. 8.2 src/Controller/ExplorerController.php \Drupal\graphql\Controller\ExplorerController::viewExplorer()

Controller for the GraphiQL query builder IDE.

Parameters

string $schema: The name of the schema.

\Symfony\Component\HttpFoundation\Request $request: The request.

Return value

array The render array. The render array.

File

src/Controller/ExplorerController.php, line 79

Class

ExplorerController
Controller for the GraphiQL query builder IDE.

Namespace

Drupal\graphql\Controller

Code

public function viewExplorer($schema, Request $request) {
  $url = $this->urlGenerator
    ->generate("graphql.query.{$schema}");
  $introspectionData = $this->introspection
    ->introspect($schema);
  return [
    '#type' => 'page',
    '#theme' => 'page__graphql_explorer',
    '#attached' => [
      'library' => [
        'graphql/explorer',
      ],
      'drupalSettings' => [
        'graphqlRequestUrl' => $url,
        'graphqlIntrospectionData' => $introspectionData,
        'graphqlQuery' => $request
          ->get('query'),
        'graphqlVariables' => $request
          ->get('variables'),
      ],
    ],
  ];
}