Skip to content

Commit 901f36c

Browse files
authored
Merge pull request #756 from astronom/auto_discover_add_built_in_option
Add auto_discover.built_in configuration option
2 parents 5579251 + 4b6f03b commit 901f36c

File tree

5 files changed

+50
-6
lines changed

5 files changed

+50
-6
lines changed

src/DependencyInjection/Compiler/ConfigParserPass.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class ConfigParserPass implements CompilerPassInterface
5656
'auto_discover' => [
5757
'root_dir' => true,
5858
'bundles' => true,
59+
'built_in' => true,
5960
],
6061
'types' => [],
6162
],
@@ -177,8 +178,8 @@ private function mappingConfig(array $config, ContainerBuilder $container): arra
177178
if ($mappingConfig['auto_discover']['bundles']) {
178179
$mappingFromBundles = $this->mappingFromBundles($container);
179180
$typesMappings = array_merge($typesMappings, $mappingFromBundles);
180-
} else {
181-
// enabled only for this bundle
181+
}
182+
if ($mappingConfig['auto_discover']['built_in']) {
182183
$typesMappings[] = [
183184
'dir' => $this->bundleDir(OverblogGraphQLBundle::class).'/Resources/config/graphql',
184185
'types' => ['yaml'],
@@ -211,6 +212,11 @@ private function mappingFromBundles(ContainerBuilder $container): array
211212

212213
// auto detect from bundle
213214
foreach ($bundles as $name => $class) {
215+
// skip this bundle
216+
if (OverblogGraphQLBundle::class === $class) {
217+
continue;
218+
}
219+
214220
$bundleDir = $this->bundleDir($class);
215221

216222
// only config files (yml or xml)

src/DependencyInjection/Configuration.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,14 @@ private function definitionsMappingsSection(): ArrayNodeDefinition
247247
$node
248248
->children()
249249
->arrayNode('auto_discover')
250-
->treatFalseLike(['bundles' => false, 'root_dir' => false])
251-
->treatTrueLike(['bundles' => true, 'root_dir' => true])
252-
->treatNullLike(['bundles' => true, 'root_dir' => true])
250+
->treatFalseLike(['bundles' => false, 'root_dir' => false, 'built_in' => true])
251+
->treatTrueLike(['bundles' => true, 'root_dir' => true, 'built_in' => true])
252+
->treatNullLike(['bundles' => true, 'root_dir' => true, 'built_in' => true])
253253
->addDefaultsIfNotSet()
254254
->children()
255255
->booleanNode('bundles')->defaultFalse()->end()
256256
->booleanNode('root_dir')->defaultFalse()->end()
257+
->booleanNode('built_in')->defaultTrue()->end()
257258
->end()
258259
->end()
259260
->arrayNode('types')

src/Generator/TypeGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function compile(int $mode): array
113113
}
114114

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

119119
// replaced hard-coded absolute paths by __DIR__
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
imports:
2+
- { resource: ../config.yml }
3+
4+
overblog_graphql:
5+
definitions:
6+
mappings:
7+
auto_discover:
8+
built_in: false
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Overblog\GraphQLBundle\Tests\Functional\DisableBuiltInMapping;
4+
5+
use GraphQL\Type\Definition\Type;
6+
use Overblog\GraphQLBundle\Resolver\UnresolvableException;
7+
use Overblog\GraphQLBundle\Tests\Functional\TestCase;
8+
9+
class DisableBuiltInMappingTest extends TestCase
10+
{
11+
protected function setUp(): void
12+
{
13+
static::bootKernel(['test_case' => 'disableBuiltInMapping']);
14+
}
15+
16+
public function testPageInfoMustNotBePresent(): void
17+
{
18+
$this->expectException(UnresolvableException::class);
19+
$this->expectExceptionMessage('Could not find type with alias "PageInfo". Did you forget to define it?');
20+
21+
$this->getType('PageInfo');
22+
}
23+
24+
private function getType(string $type): ?Type
25+
{
26+
// @phpstan-ignore-next-line
27+
return $this->getContainer()->get('overblog_graphql.type_resolver')->resolve($type);
28+
}
29+
}

0 commit comments

Comments
 (0)