|
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
|
|
|
|
|
16
|
|
|
class ProfilerController |
|
17
|
|
|
{ |
|
18
|
|
|
private ?Profiler $profiler; |
|
19
|
|
|
private ?Environment $twig; |
|
20
|
|
|
private string $endpointUrl; |
|
21
|
|
|
private RequestExecutor $requestExecutor; |
|
22
|
|
|
private ?string $queryMatch; |
|
23
|
|
|
|
|
24
|
3 |
|
public function __construct(?Profiler $profiler, ?Environment $twig, RouterInterface $router, RequestExecutor $requestExecutor, ?string $queryMatch) |
|
25
|
|
|
{ |
|
26
|
3 |
|
$this->profiler = $profiler; |
|
27
|
3 |
|
$this->twig = $twig; |
|
28
|
3 |
|
$this->endpointUrl = $router->generate('overblog_graphql_endpoint'); |
|
29
|
3 |
|
$this->requestExecutor = $requestExecutor; |
|
30
|
3 |
|
$this->queryMatch = $queryMatch; |
|
31
|
3 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @throws ServiceNotFoundException |
|
35
|
|
|
*/ |
|
36
|
3 |
|
public function __invoke(Request $request, string $token): Response |
|
37
|
|
|
{ |
|
38
|
3 |
|
if (null === $this->profiler) { |
|
39
|
1 |
|
throw new ServiceNotFoundException('The profiler must be enabled.'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
2 |
|
if (null === $this->twig) { |
|
43
|
1 |
|
throw new ServiceNotFoundException('The GraphQL Profiler require twig'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
$this->profiler->disable(); |
|
47
|
|
|
|
|
48
|
1 |
|
$profile = $this->profiler->loadProfile($token); |
|
49
|
|
|
|
|
50
|
|
|
$tokens = \array_map(function ($tokenData) { |
|
51
|
1 |
|
$profile = $this->profiler->loadProfile($tokenData['token']); |
|
|
|
|
|
|
52
|
1 |
|
$graphql = $profile ? $profile->getCollector('graphql') : null; |
|
53
|
1 |
|
$tokenData['graphql'] = $graphql; |
|
54
|
|
|
|
|
55
|
1 |
|
return $tokenData; |
|
56
|
1 |
|
}, $this->profiler->find(null, $this->queryMatch ?: $this->endpointUrl, '100', 'POST', null, null, null)); |
|
57
|
|
|
|
|
58
|
1 |
|
$schemas = []; |
|
59
|
1 |
|
foreach ($this->requestExecutor->getSchemasNames() as $schemaName) { |
|
60
|
1 |
|
$schemas[$schemaName] = SchemaPrinter::doPrint($this->requestExecutor->getSchema($schemaName)); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
1 |
|
return new Response($this->twig->render('@OverblogGraphQL/profiler/graphql.html.twig', [ |
|
64
|
1 |
|
'request' => $request, |
|
65
|
1 |
|
'profile' => $profile, |
|
66
|
1 |
|
'tokens' => $tokens, |
|
67
|
1 |
|
'token' => $token, |
|
68
|
|
|
'panel' => null, |
|
69
|
1 |
|
'schemas' => $schemas, |
|
70
|
1 |
|
]), 200, ['Content-Type' => 'text/html']); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
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.