Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions Command/GraphQLDumpSchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\ContainerInterface;

class GraphQLDumpSchemaCommand extends Command
{
/** @var RequestExecutor */
private $requestExecutor;
/** @var ContainerInterface */
private $container;

/** @var string */
private $relayVersion;
Expand All @@ -23,12 +24,12 @@ class GraphQLDumpSchemaCommand extends Command
private $baseExportPath;

public function __construct(
RequestExecutor $requestExecutor,
ContainerInterface $container,
$relayVersion,
$baseExportPath
) {
parent::__construct();
$this->requestExecutor = $requestExecutor;
$this->container = $container;
$this->relayVersion = $relayVersion;
$this->baseExportPath = $baseExportPath;
}
Expand Down Expand Up @@ -97,15 +98,15 @@ private function createFile(InputInterface $input)

$modern = $this->useModernJsonFormat($input);

$result = $this->requestExecutor
$result = $this->getRequestExecutor()
->execute($request, [], $schemaName)
->toArray();

$content = json_encode($modern ? $result : $result['data'], \JSON_PRETTY_PRINT);
break;

case 'graphql':
$content = SchemaPrinter::doPrint($this->requestExecutor->getSchema($schemaName));
$content = SchemaPrinter::doPrint($this->getRequestExecutor()->getSchema($schemaName));
break;

default:
Expand All @@ -132,4 +133,12 @@ private function useModernJsonFormat(InputInterface $input)

return $modern;
}

/**
* @return RequestExecutor
*/
private function getRequestExecutor()
{
return $this->container->get('overblog_graphql.request_executor');
}
}
5 changes: 4 additions & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ services:
overblog_graphql.command.dump_schema:
class: Overblog\GraphQLBundle\Command\GraphQLDumpSchemaCommand
arguments:
- "@overblog_graphql.request_executor"
# "overblog_graphql.request_executor" service must be load lazy since that command service
# is instanced before ClassLoaderEvent. This issues is fix in Symfony 3.4 introducing lazy commands
# see https://symfony.com/blog/new-in-symfony-3-4-lazy-commands
- '@service_container'
- "%overblog_graphql.versions.relay%"
- "%kernel.root_dir%"
tags:
Expand Down