From 1afe0685b3a19ca9ace7d009238d2d6f953409de Mon Sep 17 00:00:00 2001 From: soyuka Date: Thu, 26 Oct 2023 14:23:25 +0200 Subject: [PATCH] fix(graphql): service missing in debug mode fixes #5919 --- .../DependencyInjection/ApiPlatformExtension.php | 11 +++++++---- .../DependencyInjection/ApiPlatformExtensionTest.php | 11 +++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php b/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php index 6866edd35e4..fa16756d195 100644 --- a/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php +++ b/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php @@ -583,13 +583,16 @@ private function registerGraphQlConfiguration(ContainerBuilder $container, array $container->registerForAutoconfiguration(ErrorHandlerInterface::class) ->addTag('api_platform.graphql.error_handler'); - if (!$container->getParameter('kernel.debug')) { - return; - } - /* TODO: remove these in 4.x only one resolver factory is used and we're using providers/processors */ if ($config['event_listeners_backward_compatibility_layer'] ?? true) { + // @TODO: API Platform 3.3 trigger_deprecation('api-platform/core', '3.3', 'In API Platform 4 only one factory "api_platform.graphql.resolver.factory.item" will remain. Stages are deprecated in favor of using a provider/processor.'); + // + deprecate every service from legacy/graphql.xml $loader->load('legacy/graphql.xml'); + + if (!$container->getParameter('kernel.debug')) { + return; + } + $requestStack = new Reference('request_stack', ContainerInterface::NULL_ON_INVALID_REFERENCE); $collectionDataCollectorResolverFactory = (new Definition(DataCollectorResolverFactory::class)) ->setDecoratedService('api_platform.graphql.resolver.factory.collection') diff --git a/tests/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php b/tests/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php index 34b2ab9ba1a..0c355e9edef 100644 --- a/tests/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php +++ b/tests/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php @@ -1274,4 +1274,15 @@ public function testLegacyGraphQlConfigurationWithoutJsonFormat(): void (new ApiPlatformExtension())->load($config, $this->container); $this->assertArrayHasKey('json', $this->container->getParameter('api_platform.formats')); } + + /** + * @see https://github.com/api-platform/core/issues/5919 + */ + public function testGraphQlLegacyConfigurationInDebugMode(): void + { + $config = self::DEFAULT_CONFIG; + + (new ApiPlatformExtension())->load($config, $this->container); + $this->assertTrue($this->container->hasDefinition('api_platform.graphql.resolver.factory.item')); + } }