From d4f20c1db1efc25d91a674b8a3166462b0412632 Mon Sep 17 00:00:00 2001 From: Paul Leitmanis Date: Tue, 15 Aug 2023 12:16:57 +1000 Subject: [PATCH 1/9] Bump deps for symfony ~4.4 --- .gitignore | 3 +- .../GraphQLExtensionTest.php | 43 ++++++++++--------- composer.json | 10 +++-- phpunit.xml.dist | 40 ++++++++--------- 4 files changed, 48 insertions(+), 48 deletions(-) diff --git a/.gitignore b/.gitignore index d851bdb..5ea11e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor/ /.idea/ -composer.lock \ No newline at end of file +composer.lock +.phpunit.result.cache \ No newline at end of file diff --git a/Tests/DependencyInjection/GraphQLExtensionTest.php b/Tests/DependencyInjection/GraphQLExtensionTest.php index 7f882f1..debee25 100644 --- a/Tests/DependencyInjection/GraphQLExtensionTest.php +++ b/Tests/DependencyInjection/GraphQLExtensionTest.php @@ -2,16 +2,16 @@ namespace Youshido\GraphQLBundle\Tests\DependencyInjection; - +use PHPUnit\Framework\TestCase; use Symfony\Component\Config\FileLocator; -use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass; +use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Youshido\GraphQLBundle\DependencyInjection\GraphQLExtension; -class GraphQLExtensionTest extends \PHPUnit_Framework_TestCase +class GraphQLExtensionTest extends TestCase { public function testDefaultConfigIsUsed() { @@ -22,15 +22,17 @@ public function testDefaultConfigIsUsed() $this->assertEquals(null, $container->getParameter('graphql.logger')); $this->assertEmpty($container->getParameter('graphql.security.white_list')); $this->assertEmpty($container->getParameter('graphql.security.black_list')); - $this->assertEquals([ - 'field' => false, - 'operation' => false, - ], + $this->assertEquals( + [ + 'field' => false, + 'operation' => false, + ], $container->getParameter('graphql.security.guard_config') ); $this->assertTrue($container->getParameter('graphql.response.json_pretty')); - $this->assertEquals([ + $this->assertEquals( + [ 'Access-Control-Allow-Origin' => '*', 'Access-Control-Allow-Headers' => 'Content-Type', ], @@ -47,20 +49,21 @@ public function testDefaultCanBeOverridden() $this->assertEquals(['hello'], $container->getParameter('graphql.security.black_list')); $this->assertEquals(['world'], $container->getParameter('graphql.security.white_list')); - $this->assertEquals([ - 'field' => true, - 'operation' => true, - ], + $this->assertEquals( + [ + 'field' => true, + 'operation' => true, + ], $container->getParameter('graphql.security.guard_config') ); $this->assertFalse($container->getParameter('graphql.response.json_pretty')); - $this->assertEquals([ - 'X-Powered-By' => 'GraphQL', - ], + $this->assertEquals( + [ + 'X-Powered-By' => 'GraphQL', + ], $container->getParameter('graphql.response.headers') ); - } private function loadContainerFromFile($file, $type, array $services = array(), $skipEnvVars = false) @@ -75,7 +78,7 @@ private function loadContainerFromFile($file, $type, array $services = array(), $container->set($id, $service); } $container->registerExtension(new GraphQLExtension()); - $locator = new FileLocator(__DIR__.'/Fixtures/config/'.$type); + $locator = new FileLocator(__DIR__ . '/Fixtures/config/' . $type); switch ($type) { case 'xml': @@ -91,12 +94,12 @@ private function loadContainerFromFile($file, $type, array $services = array(), throw new \InvalidArgumentException('Invalid file type'); } - $loader->load($file.'.'.$type); + $loader->load($file . '.' . $type); $container->getCompilerPassConfig()->setOptimizationPasses(array( - new ResolveDefinitionTemplatesPass(), + new ResolveChildDefinitionsPass(), )); $container->getCompilerPassConfig()->setRemovingPasses(array()); $container->compile(); return $container; } -} \ No newline at end of file +} diff --git a/composer.json b/composer.json index acf3f24..988a75c 100644 --- a/composer.json +++ b/composer.json @@ -18,12 +18,14 @@ } }, "require": { - "php": ">=5.6", - "youshido/graphql": "~1.4" + "99designs/graphql": "~1", + "symfony/security-core": "~4.4", + "symfony/framework-bundle": "~4.4", + "php": ">=5.6" }, "require-dev": { - "phpunit/phpunit": "~4.7", + "phpunit/phpunit": "~9.6", "composer/composer": "~1.2", - "symfony/framework-bundle": "~2.7|~3.0" + "symfony/yaml": "~4.4" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b58b0f8..5e05d09 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,24 +1,18 @@ - - - - - ./Tests - - - - - - - - - - . - - ./Resources - ./Tests - ./vendor - - - - \ No newline at end of file + + + + . + + + ./Resources + ./Tests + ./vendor + + + + + ./Tests + + + From 9339a2fc0e06bf419d7ea7dd6ef7850739ae2662 Mon Sep 17 00:00:00 2001 From: Paul Leitmanis Date: Mon, 14 Aug 2023 15:59:46 +1000 Subject: [PATCH 2/9] Update TreeBuilder setup for symfony --- DependencyInjection/Configuration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index f8876d6..57c6917 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -18,8 +18,8 @@ class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('graphql'); + $treeBuilder = new TreeBuilder('graphql'); + $rootNode = $treeBuilder->getRootNode(); $rootNode ->children() From b7a6aa97984c140a2eba704414a06a75b4a758fb Mon Sep 17 00:00:00 2001 From: Florent Destremau Date: Tue, 23 Aug 2022 16:30:23 +0200 Subject: [PATCH 3/9] Updated command arguments --- Command/GraphQLConfigureCommand.php | 1 - Resources/config/services.xml | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/GraphQLConfigureCommand.php b/Command/GraphQLConfigureCommand.php index ee6c492..478a134 100644 --- a/Command/GraphQLConfigureCommand.php +++ b/Command/GraphQLConfigureCommand.php @@ -2,7 +2,6 @@ namespace Youshido\GraphQLBundle\Command; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Config\Resource\DirectoryResource; use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Console\Input\InputInterface; diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 6632101..c9ea33a 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -51,6 +51,7 @@ + From 900a2565bf5b62699757fec1abc2345f091f5bfe Mon Sep 17 00:00:00 2001 From: Florent Destremau Date: Tue, 23 Aug 2022 16:21:29 +0200 Subject: [PATCH 4/9] Updated command with symfony 5.4 --- Command/GraphQLConfigureCommand.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Command/GraphQLConfigureCommand.php b/Command/GraphQLConfigureCommand.php index 478a134..f2f4176 100644 --- a/Command/GraphQLConfigureCommand.php +++ b/Command/GraphQLConfigureCommand.php @@ -4,14 +4,21 @@ use Symfony\Component\Config\Resource\DirectoryResource; use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; +use Symfony\Component\DependencyInjection\ContainerInterface; -class GraphQLConfigureCommand extends ContainerAwareCommand +class GraphQLConfigureCommand extends Command { const PROJECT_NAMESPACE = 'App'; + public function __construct(private ContainerInterface $container) + { + parent::__construct(); + } + /** * {@inheritdoc} */ @@ -30,8 +37,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $isComposerCall = $input->getOption('composer'); - $container = $this->getContainer(); - $rootDir = $container->getParameter('kernel.root_dir'); + $rootDir = $this->container->getParameter('kernel.root_dir'); $configFile = $rootDir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'config/packages/graphql.yml'; $className = 'Schema'; @@ -104,7 +110,7 @@ protected function execute(InputInterface $input, OutputInterface $output) */ protected function getMainRouteConfig() { - $routerResources = $this->getContainer()->get('router')->getRouteCollection()->getResources(); + $routerResources = $this->container->get('router')->getRouteCollection()->getResources(); foreach ($routerResources as $resource) { /** @var FileResource|DirectoryResource $resource */ if (method_exists($resource, 'getResource') && substr($resource->getResource(), -11) == 'routes.yaml') { @@ -121,7 +127,7 @@ protected function getMainRouteConfig() */ protected function graphQLRouteExists() { - $routerResources = $this->getContainer()->get('router')->getRouteCollection()->getResources(); + $routerResources = $this->container->get('router')->getRouteCollection()->getResources(); foreach ($routerResources as $resource) { /** @var FileResource|DirectoryResource $resource */ if (method_exists($resource, 'getResource') && strpos($resource->getResource(), 'GraphQLController.php') !== false) { From 96f8ef653e7ab2e525edb56888080464863bdff4 Mon Sep 17 00:00:00 2001 From: Paul Leitmanis Date: Mon, 14 Aug 2023 16:14:12 +1000 Subject: [PATCH 5/9] Allow symfony 5.4 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 988a75c..5224f48 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,8 @@ }, "require": { "99designs/graphql": "~1", - "symfony/security-core": "~4.4", - "symfony/framework-bundle": "~4.4", + "symfony/security-core": "~4.4 || ~5.4", + "symfony/framework-bundle": "~4.4 || ~5.4", "php": ">=5.6" }, "require-dev": { From 9fc3eb31564a682317565b4e42d167c7f58d58e9 Mon Sep 17 00:00:00 2001 From: Paul Leitmanis Date: Tue, 15 Aug 2023 12:18:23 +1000 Subject: [PATCH 6/9] Rename composer package to 99designs/graphql-bundle --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5224f48..412eda9 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "youshido/graphql-bundle", + "name": "99designs/graphql-bundle", "description": "Symfony GraphQl Bundle", "license": "MIT", "authors": [ From ca90556bc4f8dca6d19fd5057c088d6c4cd04467 Mon Sep 17 00:00:00 2001 From: Paul Leitmanis Date: Tue, 15 Aug 2023 09:29:47 +1000 Subject: [PATCH 7/9] Controller fixes for symfony 5 --- Command/GraphQLConfigureCommand.php | 9 ++++-- Controller/GraphQLController.php | 50 +++++++++++++++++++---------- GraphQLBundle.php | 2 +- Resources/config/services.xml | 5 +++ 4 files changed, 46 insertions(+), 20 deletions(-) diff --git a/Command/GraphQLConfigureCommand.php b/Command/GraphQLConfigureCommand.php index f2f4176..6a2dbfb 100644 --- a/Command/GraphQLConfigureCommand.php +++ b/Command/GraphQLConfigureCommand.php @@ -8,14 +8,20 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; +use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerInterface; class GraphQLConfigureCommand extends Command { const PROJECT_NAMESPACE = 'App'; - public function __construct(private ContainerInterface $container) + /** @var Container */ + protected $container; + + public function __construct(ContainerInterface $container) { + $this->container = $container; + parent::__construct(); } @@ -140,7 +146,6 @@ protected function graphQLRouteExists() protected function generateRoutes() { - } protected function getSchemaClassTemplate($nameSpace, $className = 'Schema') diff --git a/Controller/GraphQLController.php b/Controller/GraphQLController.php index d8f7cf1..e38df1a 100644 --- a/Controller/GraphQLController.php +++ b/Controller/GraphQLController.php @@ -1,4 +1,5 @@ container = $container; + $this->params = $params; + } + /** * @Route("/graphql") * @@ -36,13 +47,13 @@ public function defaultAction() ); } - if ($this->get('request_stack')->getCurrentRequest()->getMethod() == 'OPTIONS') { + if ($this->container->get('request_stack')->getCurrentRequest()->getMethod() == 'OPTIONS') { return $this->createEmptyResponse(); } list($queries, $isMultiQueryRequest) = $this->getPayload(); - $queryResponses = array_map(function($queryData) { + $queryResponses = array_map(function ($queryData) { return $this->executeQuery($queryData['query'], $queryData['variables']); }, $queries); @@ -55,15 +66,15 @@ public function defaultAction() return $response; } - private function createEmptyResponse() + protected function createEmptyResponse() { return new JsonResponse([], 200, $this->getResponseHeaders()); } - private function executeQuery($query, $variables) + protected function executeQuery($query, $variables) { /** @var Processor $processor */ - $processor = $this->get('graphql.processor'); + $processor = $this->container->get('graphql.processor'); $processor->processPayload($query, $variables); return $processor->getResponseData(); @@ -74,9 +85,9 @@ private function executeQuery($query, $variables) * * @throws \Exception */ - private function getPayload() + protected function getPayload() { - $request = $this->get('request_stack')->getCurrentRequest(); + $request = $this->container->get('request_stack')->getCurrentRequest(); $query = $request->get('query', null); $variables = $request->get('variables', []); $isMultiQueryRequest = false; @@ -135,7 +146,7 @@ private function getPayload() /** * @throws \Exception */ - private function initializeSchemaService() + protected function initializeSchemaService() { if ($this->container->initialized('graphql.schema')) { return; @@ -149,9 +160,9 @@ private function initializeSchemaService() * * @throws \Exception */ - private function makeSchemaService() + protected function makeSchemaService() { - if ($this->container->has($this->getSchemaService())) { + if ($this->getSchemaService() && $this->container->has($this->getSchemaService())) { return $this->container->get($this->getSchemaService()); } @@ -175,7 +186,7 @@ private function makeSchemaService() /** * @return string */ - private function getSchemaClass() + protected function getSchemaClass() { return $this->getParameter('graphql.schema_class'); } @@ -183,19 +194,24 @@ private function getSchemaClass() /** * @return string */ - private function getSchemaService() + protected function getSchemaService() { $serviceName = $this->getParameter('graphql.schema_service'); - if (substr($serviceName, 0, 1) === '@') { + if (substr($serviceName ?: '', 0, 1) === '@') { return substr($serviceName, 1, strlen($serviceName) - 1); } return $serviceName; } - private function getResponseHeaders() + protected function getResponseHeaders() { return $this->getParameter('graphql.response.headers'); } + + protected function getParameter(string $name): array|bool|string|int|float|\UnitEnum|null + { + return $this->params->get($name); + } } diff --git a/GraphQLBundle.php b/GraphQLBundle.php index f4f9512..c49afb1 100644 --- a/GraphQLBundle.php +++ b/GraphQLBundle.php @@ -27,7 +27,7 @@ public function build(ContainerBuilder $container) } - public function getContainerExtension() + public function getContainerExtension(): GraphQLExtension { if (null === $this->extension) { $this->extension = new GraphQLExtension(); diff --git a/Resources/config/services.xml b/Resources/config/services.xml index c9ea33a..fa5ab83 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -53,5 +53,10 @@ + + + + + From f1563f477c9cda90897fac19cbe4c0bfd4c788b9 Mon Sep 17 00:00:00 2001 From: Paul Leitmanis Date: Tue, 15 Aug 2023 09:33:30 +1000 Subject: [PATCH 8/9] symfony/yaml 5.4 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 412eda9..0834bd0 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,6 @@ "require-dev": { "phpunit/phpunit": "~9.6", "composer/composer": "~1.2", - "symfony/yaml": "~4.4" + "symfony/yaml": "~4.4 || ~5.4" } } From 79a7233ca960f00a19ee3e7ccf805cd6bdcd1806 Mon Sep 17 00:00:00 2001 From: Paul Leitmanis Date: Tue, 15 Aug 2023 12:22:07 +1000 Subject: [PATCH 9/9] Fix GraphQLExtension for symfony 5 with type hint --- DependencyInjection/GraphQLExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DependencyInjection/GraphQLExtension.php b/DependencyInjection/GraphQLExtension.php index 81bbbaf..a635fa6 100644 --- a/DependencyInjection/GraphQLExtension.php +++ b/DependencyInjection/GraphQLExtension.php @@ -58,7 +58,7 @@ private function getDefaultHeaders() ]; } - public function getAlias() + public function getAlias(): string { return "graphql"; }