src/GraphiQLController.php
public function init()
    {
        parent::init();

        $routes = $this->findAvailableRoutes();
        $route = $this->getRequest()->getVar('endpoint') ?: $this->config()->default_route;

        // Legacy. Find the first route mapped to the controller.
        if (!$route && !empty($routes)) {
            $route = $routes[0];
        }

        if (!$route) {
            throw new \RuntimeException("There are no routes set up for a GraphQL server. You will need to add one to the SilverStripe\Control\Director.rules config setting.");
        }

        $route = trim($route, '/');
        $jsonRoutes = json_encode($routes);
        $securityID = Controller::config()->enable_csrf_protection
            ? "'" . SecurityToken::inst()->getValue() . "'"
            : 'null';
        Requirements::customScript(
            <<<JS
var GRAPHQL_ROUTE = '{$route}';
var GRAPHQL_ROUTES = $jsonRoutes;
var SECURITY_ID = $securityID;
JS
        );

        Requirements::javascript('silverstripe/graphql-devtools: client/dist/graphiql.js');
    }
public function init()
    {
        parent::init();

        $routes = $this->findAvailableRoutes();
        $route = $this->getRequest()->getVar('endpoint') ?: $this->config()->default_route;

        // Legacy. Find the first route mapped to the controller.
        if (!$route && !empty($routes)) {
            $route = $routes[0];
        }

        if (!$route) {
            throw new \RuntimeException("There are no routes set up for a GraphQL server. You will need to add one to the SilverStripe\Control\Director.rules config setting.");
        }

        $route = trim($route, '/');
        $jsonRoutes = json_encode($routes);
        $securityID = Controller::config()->enable_csrf_protection
            ? "'" . SecurityToken::inst()->getValue() . "'"
            : 'null';
        Requirements::customScript(
            <<<JS
var GRAPHQL_ROUTE = '{$route}';
var GRAPHQL_ROUTES = $jsonRoutes;
var SECURITY_ID = $securityID;
JS
        );

        Requirements::javascript('silverstripe/graphql-devtools: client/dist/graphiql.js');
    }
public function init ( ) { parent :: init ( ) ; $ routes = $ this -> findAvailableRoutes ( ) ; $ route = $ this -> getRequest ( ) -> getVar ( 'endpoint' ) ? : $ this -> config ( ) -> default_route ; // Legacy. Find the first route mapped to the controller. if ( ! $ route && ! empty ( $ routes ) ) { $ route = $ routes [ 0 ] ; } if ( ! $ route ) { throw new \ RuntimeException ( "There are no routes set up for a GraphQL server. You will need to add one to the SilverStripe\Control\Director.rules config setting." ) ; } $ route = trim ( $ route , '/' ) ; $ jsonRoutes = json_encode ( $ routes ) ; $ securityID = Controller :: config ( ) -> enable_csrf_protection ? "'" . SecurityToken :: inst ( ) -> getValue ( ) . "'" : 'null' ; Requirements :: customScript ( 
            <<<JS
var GRAPHQL_ROUTE = '{$route}';
var GRAPHQL_ROUTES = $jsonRoutes;
var SECURITY_ID = $securityID;
JS ) ; Requirements :: javascript ( 'silverstripe/graphql-devtools: client/dist/graphiql.js' ) ; }
Initialise the controller, sanity check, load javascript.
Note that permission checks are handled by DevelopmentAdmin.
Initialise the controller sanity check load javascript . Note that permission checks are handled by DevelopmentAdmin .