class ExplorerController in GraphQL 8.4
Same name and namespace in other branches
- 8 src/Controller/ExplorerController.php \Drupal\graphql\Controller\ExplorerController
- 8.2 src/Controller/ExplorerController.php \Drupal\graphql\Controller\ExplorerController
- 8.3 src/Controller/ExplorerController.php \Drupal\graphql\Controller\ExplorerController
Controller for the GraphiQL query builder IDE.
@codeCoverageIgnore
Hierarchy
- class \Drupal\graphql\Controller\ExplorerController implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of ExplorerController
File
- src/
Controller/ ExplorerController.php, line 19
Namespace
Drupal\graphql\ControllerView source
class ExplorerController implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The URL generator service.
*
* @var \Drupal\Core\Routing\UrlGeneratorInterface
*/
protected $urlGenerator;
/**
* The introspection service.
*
* @var \Drupal\graphql\GraphQL\Utility\Introspection
*/
protected $introspection;
/**
* The schema plugin manager.
*
* @var \Drupal\graphql\Plugin\SchemaPluginManager
*/
protected $pluginManager;
/**
* {@inheritdoc}
*
* @codeCoverageIgnore
*/
public static function create(ContainerInterface $container) : self {
return new static($container
->get('url_generator'), $container
->get('graphql.introspection'), $container
->get('plugin.manager.graphql.schema'));
}
/**
* ExplorerController constructor.
*
* @param \Drupal\Core\Routing\UrlGeneratorInterface $urlGenerator
* The url generator service.
* @param \Drupal\graphql\GraphQL\Utility\Introspection $introspection
* The introspection service.
* @param \Drupal\graphql\Plugin\SchemaPluginManager $pluginManager
* The schema plugin manager.
*
* @codeCoverageIgnore
*/
public function __construct(UrlGeneratorInterface $urlGenerator, Introspection $introspection, SchemaPluginManager $pluginManager) {
$this->urlGenerator = $urlGenerator;
$this->introspection = $introspection;
$this->pluginManager = $pluginManager;
}
/**
* Controller for the GraphiQL query builder IDE.
*
* @param \Drupal\graphql\Entity\ServerInterface $graphql_server
* The server.
* @param \Symfony\Component\HttpFoundation\Request $request
* The request.
*
* @return array
* The render array.
*/
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'),
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ExplorerController:: |
protected | property | The introspection service. | |
ExplorerController:: |
protected | property | The schema plugin manager. | |
ExplorerController:: |
protected | property | The URL generator service. | |
ExplorerController:: |
public static | function |
@codeCoverageIgnore Overrides ContainerInjectionInterface:: |
|
ExplorerController:: |
public | function | Controller for the GraphiQL query builder IDE. | |
ExplorerController:: |
public | function | ExplorerController constructor. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |