diff --git a/src/DependencyInjection/Compiler/ConfigParserPass.php b/src/DependencyInjection/Compiler/ConfigParserPass.php index 60635bf7a..e6d80523b 100644 --- a/src/DependencyInjection/Compiler/ConfigParserPass.php +++ b/src/DependencyInjection/Compiler/ConfigParserPass.php @@ -56,6 +56,7 @@ class ConfigParserPass implements CompilerPassInterface 'auto_discover' => [ 'root_dir' => true, 'bundles' => true, + 'built_in' => true, ], 'types' => [], ], @@ -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'], @@ -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) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index c68caf5ee..0f6fc8231 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -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') diff --git a/src/Generator/TypeGenerator.php b/src/Generator/TypeGenerator.php index 28c1ed63c..32a1109bf 100644 --- a/src/Generator/TypeGenerator.php +++ b/src/Generator/TypeGenerator.php @@ -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 = " '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); + } +}