You are here

public function ExplorerController::viewExplorer in GraphQL 8.4

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

Controller for the GraphiQL query builder IDE.

Parameters

\Drupal\graphql\Entity\ServerInterface $graphql_server: The server.

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

Return value

array The render array.

1 string reference to 'ExplorerController::viewExplorer'
graphql.routing.yml in ./graphql.routing.yml
graphql.routing.yml

File

src/Controller/ExplorerController.php, line 85

Class

ExplorerController
Controller for the GraphiQL query builder IDE.

Namespace

Drupal\graphql\Controller

Code

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