You are here

class VoyagerController in GraphQL 8.4

Same name and namespace in other branches
  1. 8.3 src/Controller/VoyagerController.php \Drupal\graphql\Controller\VoyagerController

Controller for the GraphQL Voyager visualisation API.

@codeCoverageIgnore

Hierarchy

Expanded class hierarchy of VoyagerController

File

src/Controller/VoyagerController.php, line 15

Namespace

Drupal\graphql\Controller
View source
class VoyagerController implements ContainerInjectionInterface {

  /**
   * The introspection service.
   *
   * @var \Drupal\graphql\GraphQL\Utility\Introspection
   */
  protected $introspection;

  /**
   * {@inheritdoc}
   *
   * @codeCoverageIgnore
   */
  public static function create(ContainerInterface $container) : self {
    return new static($container
      ->get('graphql.introspection'));
  }

  /**
   * VoyagerController constructor.
   *
   * @param \Drupal\graphql\GraphQL\Utility\Introspection $introspection
   *   The GraphQL introspection service.
   *
   * @codeCoverageIgnore
   */
  public function __construct(Introspection $introspection) {
    $this->introspection = $introspection;
  }

  /**
   * Display for the GraphQL Voyager visualization API.
   *
   * @param \Drupal\graphql\Entity\ServerInterface $graphql_server
   *   The server.
   *
   * @return array
   *   The render array.
   */
  public function viewVoyager(ServerInterface $graphql_server) {
    $introspectionData = $this->introspection
      ->introspect($graphql_server);
    return [
      '#type' => 'markup',
      '#markup' => '<div id="graphql-voyager"></div>',
      '#attached' => [
        'library' => [
          'graphql/voyager',
        ],
        'drupalSettings' => [
          'graphqlIntrospectionData' => $introspectionData,
        ],
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
VoyagerController::$introspection protected property The introspection service.
VoyagerController::create public static function @codeCoverageIgnore Overrides ContainerInjectionInterface::create
VoyagerController::viewVoyager public function Display for the GraphQL Voyager visualization API.
VoyagerController::__construct public function VoyagerController constructor.