vendor/api-platform/core/src/GraphQl/Action/GraphQlPlaygroundAction.php line 27

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the API Platform project.
  4.  *
  5.  * (c) Kévin Dunglas <dunglas@gmail.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace ApiPlatform\GraphQl\Action;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  15. use Symfony\Component\Routing\RouterInterface;
  16. use Twig\Environment as TwigEnvironment;
  17. /**
  18.  * GraphQL Playground entrypoint.
  19.  *
  20.  * @author Alan Poulain <contact@alanpoulain.eu>
  21.  */
  22. final class GraphQlPlaygroundAction
  23. {
  24.     private $twig;
  25.     private $router;
  26.     private $graphQlPlaygroundEnabled;
  27.     private $title;
  28.     private $assetPackage;
  29.     public function __construct(TwigEnvironment $twigRouterInterface $routerbool $graphQlPlaygroundEnabled falsestring $title ''$assetPackage null)
  30.     {
  31.         $this->twig $twig;
  32.         $this->router $router;
  33.         $this->graphQlPlaygroundEnabled $graphQlPlaygroundEnabled;
  34.         $this->title $title;
  35.         $this->assetPackage $assetPackage;
  36.     }
  37.     public function __invoke(Request $request): Response
  38.     {
  39.         if ($this->graphQlPlaygroundEnabled) {
  40.             return new Response($this->twig->render('@ApiPlatform/GraphQlPlayground/index.html.twig', [
  41.                 'title' => $this->title,
  42.                 'graphql_playground_data' => ['entrypoint' => $this->router->generate('api_graphql_entrypoint')],
  43.                 'assetPackage' => $this->assetPackage,
  44.             ]));
  45.         }
  46.         throw new BadRequestHttpException('GraphQL Playground is not enabled.');
  47.     }
  48. }
  49. class_alias(GraphQlPlaygroundAction::class, \ApiPlatform\Core\GraphQl\Action\GraphQlPlaygroundAction::class);