-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathGeneratePlatformSchemaCommand.php
More file actions
70 lines (60 loc) · 2.34 KB
/
GeneratePlatformSchemaCommand.php
File metadata and controls
70 lines (60 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace BD\EzPlatformGraphQLBundle\Command;
use BD\EzPlatformGraphQLBundle\Schema\SchemaGenerator;
use eZ\Publish\API\Repository\Repository;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Yaml\Yaml;
class GeneratePlatformSchemaCommand extends Command
{
/**
* @var \eZ\Publish\API\Repository\Repository
*/
private $repository;
/**
* @var \BD\EzPlatformGraphQLBundle\Schema\SchemaGenerator
*/
private $generator;
const TYPES_DIRECTORY = "app/config/graphql";
public function __construct(Repository $repository, SchemaGenerator $generator)
{
parent::__construct();
$this->repository = $repository;
$this->generator = $generator;
}
protected function configure()
{
$this
->setName('ezplatform:graphql:generate-schema')
->setDescription("Generates the GraphQL schema for the eZ Platform instance")
->addOption('dry-run', null, InputOption::VALUE_OPTIONAL, 'Do not write, output the schema only', false)
->addOption('include', null, InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Type to output or write', []);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$schema = $this->generator->generate();
$include = $input->getOption('include');
$doWrite = $input->getOption('dry-run') === false;
$fs = new Filesystem();
foreach ($schema as $type => $definition) {
if (count($include) && !in_array($type, $include)) {
continue;
}
$typeFilePath = self::TYPES_DIRECTORY . "/$type.types.yml";
$yaml = Yaml::dump([$type => $definition], 6);
if ($doWrite) {
$fs->dumpFile($typeFilePath, $yaml);
$output->writeln("Written $typeFilePath");
} else {
$output->writeln("\n# $type\n$yaml\n");
}
}
}
}