Skip to content

Commit de5bf52

Browse files
committed
Don't load graphql services when disabled in config
1 parent 2c7a861 commit de5bf52

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function load(array $configs, ContainerBuilder $container)
136136
$this->registerJsonLdConfiguration($container, $formats, $loader, $config['enable_docs']);
137137
$this->registerJsonHalConfiguration($formats, $loader);
138138
$this->registerJsonProblemConfiguration($errorFormats, $loader);
139-
$this->registerGraphqlConfiguration($container, $config, $loader);
139+
$this->registerGraphQlConfiguration($container, $config, $loader);
140140
$this->registerBundlesConfiguration($bundles, $config, $loader);
141141
$this->registerCacheConfiguration($container);
142142
$this->registerDoctrineConfiguration($container, $config, $loader, $useDoctrine);
@@ -401,13 +401,16 @@ private function registerJsonProblemConfiguration(array $errorFormats, XmlFileLo
401401
/**
402402
* Registers the GraphQL configuration.
403403
*/
404-
private function registerGraphqlConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader)
404+
private function registerGraphQlConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader)
405405
{
406-
if (!$config['graphql']) {
406+
$enabled = $config['graphql']['enabled'];
407+
408+
$container->setParameter('api_platform.graphql.enabled', $enabled);
409+
410+
if (!$enabled) {
407411
return;
408412
}
409413

410-
$container->setParameter('api_platform.graphql.enabled', $config['graphql']['enabled']);
411414
$container->setParameter('api_platform.graphql.graphiql.enabled', $config['graphql']['graphiql']['enabled']);
412415

413416
$loader->load('graphql.xml');

tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,20 +310,23 @@ public function testEnableNelmioApiDoc()
310310
$this->extension->load(array_merge_recursive(self::DEFAULT_CONFIG, ['api_platform' => ['enable_nelmio_api_doc' => true]]), $containerBuilder);
311311
}
312312

313-
public function testDisableGraphql()
313+
public function testDisableGraphQl()
314314
{
315315
$containerBuilderProphecy = $this->getBaseContainerBuilderProphecy();
316-
$containerBuilderProphecy->setDefinition('api_platform.action.graphql_entrypoint')->shouldNotBeCalled();
317-
$containerBuilderProphecy->setDefinition('api_platform.graphql.resolver.factory.collection')->shouldNotBeCalled();
318-
$containerBuilderProphecy->setDefinition('api_platform.graphql.resolver.factory.item_mutation')->shouldNotBeCalled();
319-
$containerBuilderProphecy->setDefinition('api_platform.graphql.resolver.item')->shouldNotBeCalled();
320-
$containerBuilderProphecy->setDefinition('api_platform.graphql.resolver.resource_field')->shouldNotBeCalled();
321-
$containerBuilderProphecy->setDefinition('api_platform.graphql.executor')->shouldNotBeCalled();
322-
$containerBuilderProphecy->setDefinition('api_platform.graphql.schema_builder')->shouldNotBeCalled();
323-
$containerBuilderProphecy->setDefinition('api_platform.graphql.normalizer.item')->shouldNotBeCalled();
324-
$containerBuilderProphecy->setDefinition('api_platform.graphql.normalizer.item.non_resource')->shouldNotBeCalled();
316+
$containerBuilderProphecy->setDefinition('api_platform.graphql.action.entrypoint', Argument::type(Definition::class))->shouldNotBeCalled();
317+
$containerBuilderProphecy->setDefinition('api_platform.graphql.resolver.factory.collection', Argument::type(Definition::class))->shouldNotBeCalled();
318+
$containerBuilderProphecy->setDefinition('api_platform.graphql.resolver.factory.item_mutation', Argument::type(Definition::class))->shouldNotBeCalled();
319+
$containerBuilderProphecy->setDefinition('api_platform.graphql.resolver.item', Argument::type(Definition::class))->shouldNotBeCalled();
320+
$containerBuilderProphecy->setDefinition('api_platform.graphql.resolver.resource_field', Argument::type(Definition::class))->shouldNotBeCalled();
321+
$containerBuilderProphecy->setDefinition('api_platform.graphql.executor', Argument::type(Definition::class))->shouldNotBeCalled();
322+
$containerBuilderProphecy->setDefinition('api_platform.graphql.schema_builder', Argument::type(Definition::class))->shouldNotBeCalled();
323+
$containerBuilderProphecy->setDefinition('api_platform.graphql.normalizer.item', Argument::type(Definition::class))->shouldNotBeCalled();
324+
$containerBuilderProphecy->setDefinition('api_platform.graphql.normalizer.item.non_resource', Argument::type(Definition::class))->shouldNotBeCalled();
325325
$containerBuilderProphecy->setParameter('api_platform.graphql.enabled', true)->shouldNotBeCalled();
326326
$containerBuilderProphecy->setParameter('api_platform.graphql.enabled', false)->shouldBeCalled();
327+
$containerBuilderProphecy->setParameter('api_platform.graphql.graphiql.enabled', true)->shouldNotBeCalled();
328+
$containerBuilderProphecy->setParameter('api_platform.graphql.graphiql.enabled', false)->shouldNotBeCalled();
329+
327330
$containerBuilder = $containerBuilderProphecy->reveal();
328331

329332
$this->extension->load(array_merge_recursive(self::DEFAULT_CONFIG, ['api_platform' => ['graphql' => ['enabled' => false]]]), $containerBuilder);

0 commit comments

Comments
 (0)