1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the OverblogGraphQLBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Overblog <http://github.com/overblog/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Overblog\GraphQLBundle\Command; |
13
|
|
|
|
14
|
|
|
use GraphQL\Type\Introspection; |
15
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
17
|
|
|
use Symfony\Component\Console\Input\InputOption; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
20
|
|
|
|
21
|
|
|
class GraphDumpSchemaCommand extends ContainerAwareCommand |
22
|
|
|
{ |
23
|
1 |
|
protected function configure() |
24
|
|
|
{ |
25
|
1 |
|
$this |
26
|
1 |
|
->setName('graph:dump-schema') |
27
|
1 |
|
->setDescription('Dumps GraphQL schema') |
28
|
1 |
|
->addOption( |
29
|
1 |
|
'file', |
30
|
1 |
|
null, |
31
|
1 |
|
InputOption::VALUE_OPTIONAL, |
32
|
|
|
'Path to generate schema file.' |
33
|
1 |
|
); |
34
|
1 |
|
} |
35
|
|
|
|
36
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
37
|
|
|
{ |
38
|
1 |
|
$output = new SymfonyStyle($input, $output); |
39
|
|
|
|
40
|
|
|
$request = [ |
41
|
1 |
|
'query' => Introspection::getIntrospectionQuery(false), |
42
|
1 |
|
'variables' => [], |
43
|
1 |
|
'operationName' => null, |
44
|
1 |
|
]; |
45
|
|
|
|
46
|
1 |
|
$container = $this->getContainer(); |
47
|
|
|
$result = $container |
48
|
1 |
|
->get('overblog_graphql.request_executor') |
49
|
1 |
|
->execute($request) |
50
|
1 |
|
->toArray(); |
51
|
|
|
|
52
|
1 |
|
$file = $input->hasOption('file') ? $input->getOption('file') : $container->getParameter('kernel.root_dir').'/../var/schema.json'; |
53
|
|
|
|
54
|
1 |
|
$schema = json_encode($result['data']); |
55
|
|
|
|
56
|
1 |
|
file_put_contents($file, $schema); |
57
|
|
|
|
58
|
1 |
|
$output->success(sprintf('GraphQL schema "%s" was successfully dumped.', realpath($file))); |
59
|
1 |
|
} |
60
|
|
|
} |
61
|
|
|
|