|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Overblog\GraphQLBundle\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use GraphQL\Utils\SchemaPrinter; |
|
8
|
|
|
use Overblog\GraphQLBundle\Request\Executor as RequestExecutor; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
12
|
|
|
use Symfony\Component\HttpKernel\Profiler\Profiler; |
|
13
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
14
|
|
|
use Twig\Environment; |
|
15
|
|
|
use Twig\Error\LoaderError; |
|
16
|
|
|
use Twig\Error\RuntimeError; |
|
17
|
|
|
use Twig\Error\SyntaxError; |
|
18
|
|
|
use function array_map; |
|
19
|
|
|
|
|
20
|
|
|
class ProfilerController |
|
21
|
|
|
{ |
|
22
|
|
|
private ?Profiler $profiler; |
|
23
|
|
|
private ?Environment $twig; |
|
24
|
|
|
private string $endpointUrl; |
|
25
|
|
|
private RequestExecutor $requestExecutor; |
|
26
|
|
|
private ?string $queryMatch; |
|
27
|
|
|
|
|
28
|
3 |
|
public function __construct(?Profiler $profiler, ?Environment $twig, RouterInterface $router, RequestExecutor $requestExecutor, ?string $queryMatch) |
|
29
|
|
|
{ |
|
30
|
3 |
|
$this->profiler = $profiler; |
|
31
|
3 |
|
$this->twig = $twig; |
|
32
|
3 |
|
$this->endpointUrl = $router->generate('overblog_graphql_endpoint'); |
|
33
|
3 |
|
$this->requestExecutor = $requestExecutor; |
|
34
|
3 |
|
$this->queryMatch = $queryMatch; |
|
35
|
3 |
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @throws LoaderError |
|
39
|
|
|
* @throws RuntimeError |
|
40
|
|
|
* @throws SyntaxError |
|
41
|
|
|
*/ |
|
42
|
3 |
|
public function __invoke(Request $request, string $token): Response |
|
43
|
|
|
{ |
|
44
|
3 |
|
if (null === $this->profiler) { |
|
45
|
1 |
|
throw new ServiceNotFoundException('The profiler must be enabled.'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
2 |
|
if (null === $this->twig) { |
|
49
|
1 |
|
throw new ServiceNotFoundException('The GraphQL Profiler require twig'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
1 |
|
$this->profiler->disable(); |
|
53
|
|
|
|
|
54
|
1 |
|
$profile = $this->profiler->loadProfile($token); |
|
55
|
|
|
|
|
56
|
1 |
|
$tokens = array_map(function ($tokenData) { |
|
57
|
1 |
|
$profile = $this->profiler->loadProfile($tokenData['token']); |
|
|
|
|
|
|
58
|
1 |
|
if (!$profile->hasCollector('graphql')) { |
|
59
|
|
|
return false; |
|
60
|
|
|
} |
|
61
|
1 |
|
$tokenData['graphql'] = $profile->getCollector('graphql'); |
|
62
|
|
|
|
|
63
|
1 |
|
return $tokenData; |
|
64
|
1 |
|
}, $this->profiler->find(null, $this->queryMatch ?: $this->endpointUrl, '100', 'POST', null, null, null)); // @phpstan-ignore-line |
|
65
|
|
|
|
|
66
|
1 |
|
$schemas = []; |
|
67
|
1 |
|
foreach ($this->requestExecutor->getSchemasNames() as $schemaName) { |
|
68
|
1 |
|
$schemas[$schemaName] = SchemaPrinter::doPrint($this->requestExecutor->getSchema($schemaName)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
return new Response($this->twig->render('@OverblogGraphQL/profiler/graphql.html.twig', [ |
|
72
|
1 |
|
'request' => $request, |
|
73
|
1 |
|
'profile' => $profile, |
|
74
|
1 |
|
'tokens' => array_filter($tokens), |
|
75
|
1 |
|
'token' => $token, |
|
76
|
|
|
'panel' => null, |
|
77
|
1 |
|
'schemas' => $schemas, |
|
78
|
1 |
|
]), 200, ['Content-Type' => 'text/html']); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.