Skip to content
Closed
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
22 changes: 20 additions & 2 deletions Definition/Builder/SchemaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use GraphQL\Schema;
use GraphQL\Type\Definition\Config;
use GraphQL\Type\LazyResolution;
use Overblog\GraphQLBundle\Resolver\ResolverInterface;

class SchemaBuilder
Expand All @@ -22,12 +23,29 @@ class SchemaBuilder
*/
private $typeResolver;

/**
* @var array
*/
private $schemaDescriptor;

/** @var bool */
private $enableValidation;

public function __construct(ResolverInterface $typeResolver, $enableValidation = false)
/**
* SchemaBuilder constructor.
*
* @param ResolverInterface $typeResolver
* @param array $schemaDescriptor
* @param bool $enableValidation
*/
public function __construct(
ResolverInterface $typeResolver,
array $schemaDescriptor,
$enableValidation = false
)
{
$this->typeResolver = $typeResolver;
$this->schemaDescriptor = $schemaDescriptor;
$this->enableValidation = $enableValidation;
}

Expand All @@ -50,7 +68,7 @@ public function create($queryAlias = null, $mutationAlias = null, $subscriptionA
'query' => $query,
'mutation' => $mutation,
'subscription' => $subscription,
'types' => $this->typeResolver->getSolutions(),
'typeResolution' => new LazyResolution($this->schemaDescriptor, [$this->typeResolver, 'resolve'])
]);
}
}
10 changes: 1 addition & 9 deletions DependencyInjection/Compiler/TaggedServiceMappingPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,7 @@ public function process(ContainerBuilder $container)
$resolverDefinition = $container->findDefinition($this->getResolverServiceID());

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

$definition = $container->findDefinition($solutionID);
if (is_subclass_of($definition->getClass(), 'Symfony\Component\DependencyInjection\ContainerAwareInterface')) {
$solutionDefinition = $container->findDefinition($options['id']);
$solutionDefinition->addMethodCall('setContainer', [new Reference('service_container')]);
}
$resolverDefinition->addMethodCall('addSolution', [$name, new Reference($solutionID), $cleanOptions]);
$resolverDefinition->addMethodCall('addSolution', [$name, null, $options]);
}
}

Expand Down
38 changes: 38 additions & 0 deletions DependencyInjection/Compiler/TypesPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,44 @@ public function process(ContainerBuilder $container)
->addTag('overblog_graphql.type', ['alias' => $name])
;
}

$types = [
'__Schema' => 1,
'__Type' => 1,
'__TypeKind' => 1,
'__Field' => 1,
'__InputValue' => 1,
'__EnumValue' => 1,
'__Directive' => 1,
'__DirectiveLocation' => 1
];
$possibleTypes = [];

foreach ($config as $typeConf) {
$typeName = $typeConf['config']['name'];
$types[$typeName] = 1;
if ($typeConf['type'] == 'object') {
$ifaces = $typeConf['config']['interfaces'] ?? [];
foreach ($ifaces as $iface) {
if (!array_key_exists($iface, $possibleTypes)) {
$possibleTypes[$iface] = [];
}
$possibleTypes[$iface][$typeName] = 1;
}
}
if ($typeConf['type'] == 'union') {
$possibleTypes[$typeName] = [];
foreach ($typeConf['config']['types'] as $unionMember) {
$possibleTypes[$typeName][$unionMember] = 1;
}
}
}

$container->getDefinition('overblog_graphql.schema_builder')->replaceArgument(1, [
'typeMap' => $types,
'possibleTypeMap' => $possibleTypes,
'version' => '1.0'
]);
}

private function processConfig(array $configs)
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getConfigTreeBuilder()
->prototype('array')
->addDefaultsIfNotSet()
->children()
->enumNode('type')->isRequired()->values(['yml', 'xml'])->end()
->enumNode('type')->isRequired()->values(['yml', 'xml', 'graphqls'])->end()
->scalarNode('dir')->defaultNull()->end()
->end()
->end()
Expand Down
Loading