1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the API Platform project. |
5
|
|
|
* |
6
|
|
|
* (c) Kévin Dunglas <[email protected]> |
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
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace ApiPlatform\Core\Bridge\Symfony\Bundle\Command; |
15
|
|
|
|
16
|
|
|
use ApiPlatform\Core\GraphQl\Type\SchemaBuilder; |
17
|
|
|
use GraphQL\Utils\SchemaPrinter; |
18
|
|
|
use Symfony\Component\Console\Command\Command; |
19
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
20
|
|
|
use Symfony\Component\Console\Input\InputOption; |
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Print the GraphQL schema in Schema Definition Language (SDL). |
25
|
|
|
* |
26
|
|
|
* @experimental |
27
|
|
|
* |
28
|
|
|
* @author Alan Poulain <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
class GraphQlSchemaPrintCommand extends Command |
31
|
|
|
{ |
32
|
|
|
protected static $defaultName = 'api:graphql:print-schema'; |
33
|
|
|
|
34
|
|
|
private $schemaBuilder; |
35
|
|
|
|
36
|
|
|
public function __construct(SchemaBuilder $schemaBuilder) |
37
|
|
|
{ |
38
|
|
|
$this->schemaBuilder = $schemaBuilder; |
39
|
|
|
|
40
|
|
|
parent::__construct(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
|
|
protected function configure(): void |
47
|
|
|
{ |
48
|
|
|
$this |
49
|
|
|
->setDescription('Print the GraphQL schema in Schema Definition Language (SDL)') |
50
|
|
|
->addOption('comment-descriptions', null, InputOption::VALUE_NONE, 'Use preceding comments as the description') |
51
|
|
|
; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): void |
58
|
|
|
{ |
59
|
|
|
$options = []; |
60
|
|
|
|
61
|
|
|
if ($input->getOption('comment-descriptions')) { |
62
|
|
|
$options['commentDescriptions'] = true; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$output->writeln(SchemaPrinter::doPrint($this->schemaBuilder->getSchema(), $options)); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|