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
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,25 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class GraphDumpSchemaCommand extends ContainerAwareCommand
class GraphQLDumpSchemaCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('graph:dump-schema')
->setName('graphql:dump-schema')
->setAliases(['graph:dump-schema'])
->setDescription('Dumps GraphQL schema')
->addOption(
'file',
null,
InputOption::VALUE_OPTIONAL,
'Path to generate schema file.'
)
->addOption(
'schema',
null,
InputOption::VALUE_OPTIONAL,
'The schema name to generate.'
);
}

Expand All @@ -42,14 +49,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
'variables' => [],
'operationName' => null,
];
$schemaName = $input->getOption('schema');

$container = $this->getContainer();
$result = $container
->get('overblog_graphql.request_executor')
->execute($request)
->execute($request, [], $schemaName)
->toArray();

$file = $input->getOption('file') ?: $container->getParameter('kernel.root_dir').'/../var/schema.json';
$file = $input->getOption('file') ?: $container->getParameter('kernel.root_dir').sprintf('/../var/schema%s.json', $schemaName? '.'.$schemaName:'');

$schema = json_encode($result['data']);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ protected function getParameterName()
{
return 'overblog_graphql.mutations_mapping';
}

protected function getResolverServiceID()
{
return 'overblog_graphql.mutation_resolver';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ protected function checkRequirements($id, array $tag)
);
}
}

protected function getResolverServiceID()
{
return 'overblog_graphql.resolver_resolver';
}
}
25 changes: 19 additions & 6 deletions DependencyInjection/Compiler/TaggedServiceMappingPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
namespace Overblog\GraphQLBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

abstract class TaggedServiceMappingPass implements CompilerPassInterface
{
Expand All @@ -32,14 +34,23 @@ private function getTaggedServiceMapping(ContainerBuilder $container, $tagName)
return $serviceMapping;
}

private function taggedServiceToParameterMapping(ContainerBuilder $container, $tagName, $parameterName)
{
$container->setParameter($parameterName, $this->getTaggedServiceMapping($container, $tagName));
}

public function process(ContainerBuilder $container)
{
$this->taggedServiceToParameterMapping($container, $this->getTagName(), $this->getParameterName());
$mapping = $this->getTaggedServiceMapping($container, $this->getTagName());
$container->setParameter($this->getParameterName(), $mapping);
$resolverDefinition = $container->findDefinition($this->getResolverServiceID());

foreach ($mapping as $name => $options) {
$cleanOptions = $options;
$solutionID = $options['id'];
$solution = $container->get($solutionID);

if ($solution instanceof ContainerAwareInterface) {
$solutionDefinition = $container->findDefinition($options['id']);
$solutionDefinition->addMethodCall('setContainer', [new Reference('service_container')]);
}
$resolverDefinition->addMethodCall('addSolution', [$name, new Reference($solutionID), $cleanOptions]);
}
}

protected function checkRequirements($id, array $tag)
Expand All @@ -53,5 +64,7 @@ protected function checkRequirements($id, array $tag)

abstract protected function getTagName();

abstract protected function getResolverServiceID();

abstract protected function getParameterName();
}
5 changes: 5 additions & 0 deletions DependencyInjection/Compiler/TypeTaggedServiceMappingPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ protected function getParameterName()
{
return 'overblog_graphql.types_mapping';
}

protected function getResolverServiceID()
{
return 'overblog_graphql.type_resolver';
}
}
59 changes: 0 additions & 59 deletions DependencyInjection/Configurator/ResolverConfigurator.php

This file was deleted.

11 changes: 0 additions & 11 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,18 @@ services:

overblog_graphql.type_resolver:
class: Overblog\GraphQLBundle\Resolver\TypeResolver
configurator: ["@overblog_graphql.resolver_configurator", "configureType"]
arguments:
-

overblog_graphql.resolver_resolver:
class: Overblog\GraphQLBundle\Resolver\ResolverResolver
configurator: ["@overblog_graphql.resolver_configurator", "configureResolver"]

overblog_graphql.mutation_resolver:
class: Overblog\GraphQLBundle\Resolver\MutationResolver
configurator: ["@overblog_graphql.resolver_configurator", "configureMutation"]

overblog_graphql.access_resolver:
class: Overblog\GraphQLBundle\Resolver\AccessResolver

overblog_graphql.resolver_configurator:
class: Overblog\GraphQLBundle\DependencyInjection\Configurator\ResolverConfigurator
calls:
- ["setContainer", ["@service_container"]]
- ["addMapping", ["type", "%overblog_graphql.types_mapping%"]]
- ["addMapping", ["resolver", "%overblog_graphql.resolvers_mapping%"]]
- ["addMapping", ["mutation", "%overblog_graphql.mutations_mapping%"]]

overblog_graphql.cache_expression_language_parser.default:
class: Symfony\Component\ExpressionLanguage\ParserCache\ArrayParserCache
public: false
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Command/GraphDumpSchemaCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Overblog\GraphQLBundle\Tests\Functional\Command;

use Overblog\GraphQLBundle\Command\GraphDumpSchemaCommand;
use Overblog\GraphQLBundle\Command\GraphQLDumpSchemaCommand;
use Overblog\GraphQLBundle\Tests\Functional\TestCase;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
Expand All @@ -24,7 +24,7 @@ public function testExecute()
$kernel = $client->getKernel();

$application = new Application($kernel);
$application->add(new GraphDumpSchemaCommand());
$application->add(new GraphQLDumpSchemaCommand());

$command = $application->find('graph:dump-schema');
$file = $kernel->getCacheDir().'/schema.json';
Expand Down