ynloultratech /
graphql-bundle
| 1 | <?php |
||||
| 2 | /******************************************************************************* |
||||
| 3 | * This file is part of the GraphQL Bundle package. |
||||
| 4 | * |
||||
| 5 | * (c) YnloUltratech <[email protected]> |
||||
| 6 | * |
||||
| 7 | * For the full copyright and license information, please view the LICENSE |
||||
| 8 | * file that was distributed with this source code. |
||||
| 9 | ******************************************************************************/ |
||||
| 10 | |||||
| 11 | namespace Ynlo\GraphQLBundle\Command; |
||||
| 12 | |||||
| 13 | use Symfony\Component\Console\Command\Command; |
||||
| 14 | use Symfony\Component\Console\Input\InputInterface; |
||||
| 15 | use Symfony\Component\Console\Input\InputOption; |
||||
| 16 | use Symfony\Component\Console\Output\OutputInterface; |
||||
| 17 | use Ynlo\GraphQLBundle\Definition\Registry\DefinitionRegistry; |
||||
| 18 | use Ynlo\GraphQLBundle\Schema\SchemaExporter; |
||||
| 19 | |||||
| 20 | class SchemaExportCommand extends Command |
||||
| 21 | { |
||||
| 22 | /** |
||||
| 23 | * @var SchemaExporter |
||||
| 24 | */ |
||||
| 25 | protected $exporter; |
||||
| 26 | |||||
| 27 | /** |
||||
| 28 | * @var DefinitionRegistry |
||||
| 29 | */ |
||||
| 30 | protected $definitionRegistry; |
||||
| 31 | |||||
| 32 | /** |
||||
| 33 | * GraphQLSchemaExportCommand constructor. |
||||
| 34 | * |
||||
| 35 | * @param SchemaExporter $exporter |
||||
| 36 | * @param DefinitionRegistry $definitionRegistry |
||||
| 37 | */ |
||||
| 38 | public function __construct(SchemaExporter $exporter, DefinitionRegistry $definitionRegistry) |
||||
| 39 | { |
||||
| 40 | $this->exporter = $exporter; |
||||
| 41 | $this->definitionRegistry = $definitionRegistry; |
||||
| 42 | |||||
| 43 | parent::__construct(); |
||||
| 44 | } |
||||
| 45 | |||||
| 46 | /** |
||||
| 47 | * {@inheritDoc} |
||||
| 48 | */ |
||||
| 49 | protected function configure() |
||||
| 50 | { |
||||
| 51 | $this->setName('graphql:schema:export') |
||||
| 52 | ->setDescription('Export your schema.') |
||||
| 53 | ->addOption('endpoint', null, InputOption::VALUE_REQUIRED, 'Name of the endpoint to export', DefinitionRegistry::DEFAULT_ENDPOINT) |
||||
| 54 | ->addOption('output', 'o', InputOption::VALUE_REQUIRED, 'Name of the file to save the schema, e.i. schema.graphql or schema.json') |
||||
| 55 | ->addOption('json', null, InputOption::VALUE_NONE, 'Create json output, automatically used if the output contains json extension'); |
||||
| 56 | } |
||||
| 57 | |||||
| 58 | /** |
||||
| 59 | * {@inheritDoc} |
||||
| 60 | */ |
||||
| 61 | protected function execute(InputInterface $input, OutputInterface $output) |
||||
| 62 | { |
||||
| 63 | $endpoint = $input->getOption('endpoint'); |
||||
| 64 | $asJson = $input->getOption('json'); |
||||
| 65 | $outputName = $input->getOption('output'); |
||||
| 66 | if (preg_match('/\.json$/', $outputName)) { |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 67 | $asJson = true; |
||||
| 68 | } |
||||
| 69 | |||||
| 70 | $schema = $this->exporter->export($this->definitionRegistry->getEndpoint($endpoint), $asJson); |
||||
|
0 ignored issues
–
show
It seems like
$endpoint can also be of type string[]; however, parameter $name of Ynlo\GraphQLBundle\Defin...Registry::getEndpoint() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 71 | if ($outputName) { |
||||
| 72 | file_put_contents($outputName, $schema); |
||||
| 73 | } else { |
||||
| 74 | $output->write($schema); |
||||
| 75 | } |
||||
| 76 | } |
||||
| 77 | } |
||||
| 78 |