Skip to content

Add auto_discover.built_in configuration option #756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2020
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
10 changes: 8 additions & 2 deletions src/DependencyInjection/Compiler/ConfigParserPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ConfigParserPass implements CompilerPassInterface
'auto_discover' => [
'root_dir' => true,
'bundles' => true,
'built_in' => true,
],
'types' => [],
],
Expand Down Expand Up @@ -177,8 +178,8 @@ private function mappingConfig(array $config, ContainerBuilder $container): arra
if ($mappingConfig['auto_discover']['bundles']) {
$mappingFromBundles = $this->mappingFromBundles($container);
$typesMappings = array_merge($typesMappings, $mappingFromBundles);
} else {
// enabled only for this bundle
}
if ($mappingConfig['auto_discover']['built_in']) {
$typesMappings[] = [
'dir' => $this->bundleDir(OverblogGraphQLBundle::class).'/Resources/config/graphql',
'types' => ['yaml'],
Expand Down Expand Up @@ -211,6 +212,11 @@ private function mappingFromBundles(ContainerBuilder $container): array

// auto detect from bundle
foreach ($bundles as $name => $class) {
// skip this bundle
if (OverblogGraphQLBundle::class === $class) {
continue;
}

$bundleDir = $this->bundleDir($class);

// only config files (yml or xml)
Expand Down
7 changes: 4 additions & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,14 @@ private function definitionsMappingsSection(): ArrayNodeDefinition
$node
->children()
->arrayNode('auto_discover')
->treatFalseLike(['bundles' => false, 'root_dir' => false])
->treatTrueLike(['bundles' => true, 'root_dir' => true])
->treatNullLike(['bundles' => true, 'root_dir' => true])
->treatFalseLike(['bundles' => false, 'root_dir' => false, 'built_in' => true])
->treatTrueLike(['bundles' => true, 'root_dir' => true, 'built_in' => true])
->treatNullLike(['bundles' => true, 'root_dir' => true, 'built_in' => true])
->addDefaultsIfNotSet()
->children()
->booleanNode('bundles')->defaultFalse()->end()
->booleanNode('root_dir')->defaultFalse()->end()
->booleanNode('built_in')->defaultTrue()->end()
->end()
->end()
->arrayNode('types')
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/TypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function compile(int $mode): array
}

// Create class map file
if ($writeMode && $this->useClassMap) {
if ($writeMode && $this->useClassMap && count($classes) > 0) {
$content = "<?php\nreturn ".var_export($classes, true).';';

// replaced hard-coded absolute paths by __DIR__
Expand Down
8 changes: 8 additions & 0 deletions tests/Functional/App/config/disableBuiltInMapping/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
imports:
- { resource: ../config.yml }

overblog_graphql:
definitions:
mappings:
auto_discover:
built_in: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Overblog\GraphQLBundle\Tests\Functional\DisableBuiltInMapping;

use GraphQL\Type\Definition\Type;
use Overblog\GraphQLBundle\Resolver\UnresolvableException;
use Overblog\GraphQLBundle\Tests\Functional\TestCase;

class DisableBuiltInMappingTest extends TestCase
{
protected function setUp(): void
{
static::bootKernel(['test_case' => 'disableBuiltInMapping']);
}

public function testPageInfoMustNotBePresent(): void
{
$this->expectException(UnresolvableException::class);
$this->expectExceptionMessage('Could not find type with alias "PageInfo". Did you forget to define it?');

$this->getType('PageInfo');
}

private function getType(string $type): ?Type
{
// @phpstan-ignore-next-line
return $this->getContainer()->get('overblog_graphql.type_resolver')->resolve($type);
}
}