Skip to content

Commit fd610e0

Browse files
author
Bertrand Dunogier
committed
Renamed the generation command to ezplatform:graphql:generate-schema (#56)
1 parent 627500a commit fd610e0

3 files changed

Lines changed: 94 additions & 51 deletions

File tree

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,39 @@
11
<?php
2-
/**
3-
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
4-
* @license For full copyright and license information view LICENSE file distributed with this source code.
5-
*/
62
namespace BD\EzPlatformGraphQLBundle\Command;
73

84
use BD\EzPlatformGraphQLBundle\Schema\SchemaGenerator;
95
use eZ\Publish\API\Repository\Repository;
10-
use Symfony\Component\Console\Command\Command;
116
use Symfony\Component\Console\Input\InputInterface;
12-
use Symfony\Component\Console\Input\InputOption;
137
use Symfony\Component\Console\Output\OutputInterface;
14-
use Symfony\Component\Filesystem\Filesystem;
15-
use Symfony\Component\Yaml\Yaml;
168

17-
class GeneratePlatformDomainTypesCommand extends Command
9+
/**
10+
* @deprecated replaced by ezplatform:graphql:generate-schema
11+
*/
12+
class GeneratePlatformDomainTypesCommand extends GeneratePlatformSchemaCommand
1813
{
19-
/**
20-
* @var \eZ\Publish\API\Repository\Repository
21-
*/
22-
private $repository;
23-
24-
/**
25-
* @var \BD\EzPlatformGraphQLBundle\Schema\SchemaGenerator
26-
*/
27-
private $generator;
28-
29-
const TYPES_DIRECTORY = "src/AppBundle/Resources/config/graphql";
30-
3114
public function __construct(Repository $repository, SchemaGenerator $generator)
3215
{
33-
parent::__construct();
34-
$this->repository = $repository;
35-
$this->generator = $generator;
16+
parent::__construct($repository, $generator);
3617
}
3718

3819
protected function configure()
3920
{
40-
$this
41-
->setName('bd:platform-graphql:generate-domain-schema')
42-
->addOption('dry-run', null, InputOption::VALUE_OPTIONAL, '', false)
43-
->addOption('include', null, InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, '', []);
21+
parent::configure();
22+
23+
$this->setName('bd:platform-graphql:generate-domain-schema');
4424
}
4525

4626
protected function execute(InputInterface $input, OutputInterface $output)
4727
{
48-
$schema = $this->generator->generate();
49-
50-
$include = $input->getOption('include');
51-
$doWrite = $input->getOption('dry-run') === false;
28+
@trigger_error(
29+
"The command name bd:platform-graphql:generate-domain-schema is deprecated. Use ezplatform:graphql:generate-schema instead.",
30+
E_USER_DEPRECATED
31+
);
5232

53-
$fs = new Filesystem();
54-
foreach ($schema as $type => $definition) {
55-
if (count($include) && !in_array($type, $include)) {
56-
continue;
57-
}
58-
$typeFilePath = self::TYPES_DIRECTORY . "/$type.types.yml";
33+
parent::execute($input, $output);
5934

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

Resources/config/services.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
services:
2-
bd_ezplatform_graphql.command.generate_platform_domain_schema:
2+
BD\EzPlatformGraphQLBundle\Command\GeneratePlatformDomainTypesCommand:
3+
autoconfigure: true
4+
autowire: true
5+
tags:
6+
- { name: console.command }
7+
8+
BD\EzPlatformGraphQLBundle\Command\GeneratePlatformSchemaCommand:
39
autoconfigure: true
410
autowire: true
5-
class: BD\EzPlatformGraphQLBundle\Command\GeneratePlatformDomainTypesCommand
6-
arguments:
7-
- "@ezpublish.api.repository"
811
tags:
912
- { name: console.command }
1013

0 commit comments

Comments
 (0)