From 30eccf200ae2ee096f3ddf6c98f791fd34758226 Mon Sep 17 00:00:00 2001 From: Dorian Savina Date: Thu, 28 Oct 2021 16:41:56 +0200 Subject: [PATCH 01/10] Rename 'Graphqlite' to 'GraphQLite' --- README.md | 2 +- composer.json | 4 ++-- src/Annotations/Assertion.php | 2 +- src/ConstraintViolationException.php | 2 +- .../Parameters/AssertParameterMiddleware.php | 4 ++-- .../InvalidAssertionAnnotationException.php | 2 +- src/Mappers/Parameters/ParameterValidator.php | 4 ++-- src/ValidationFailedException.php | 2 +- tests/Annotations/AssertionTest.php | 2 +- tests/ConstraintValidationExceptionTest.php | 2 +- tests/Fixtures/Controllers/UserController.php | 8 ++++---- .../InvalidControllers/InvalidController.php | 4 ++-- tests/Fixtures/Types/User.php | 2 +- tests/IntegrationTest.php | 16 ++++++++-------- tests/ValidationFailedExceptionTest.php | 2 +- 15 files changed, 29 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 83d0ab4..960c873 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Coverage Status](https://coveralls.io/repos/thecodingmachine/graphqlite-symfony-validator-bridge/badge.svg?branch=master&service=github)](https://coveralls.io/github/thecodingmachine/graphqlite-symfony-validator-bridge?branch=master) -# Graphqlite - Symfony validator bridge +# GraphQLite - Symfony validator bridge A bridge between GraphQLite and the Symfony Validator component diff --git a/composer.json b/composer.json index 73f7040..896faf6 100644 --- a/composer.json +++ b/composer.json @@ -38,12 +38,12 @@ }, "autoload" : { "psr-4" : { - "TheCodingMachine\\Graphqlite\\Validator\\" : "src/" + "TheCodingMachine\\GraphQLite\\Validator\\" : "src/" } }, "autoload-dev" : { "psr-4" : { - "TheCodingMachine\\Graphqlite\\Validator\\" : "tests/" + "TheCodingMachine\\GraphQLite\\Validator\\" : "tests/" } }, "extra": { diff --git a/src/Annotations/Assertion.php b/src/Annotations/Assertion.php index b12fcfc..3220c53 100644 --- a/src/Annotations/Assertion.php +++ b/src/Annotations/Assertion.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace TheCodingMachine\Graphqlite\Validator\Annotations; +namespace TheCodingMachine\GraphQLite\Validator\Annotations; use BadMethodCallException; use Symfony\Component\Validator\Constraint; diff --git a/src/ConstraintViolationException.php b/src/ConstraintViolationException.php index ebcd09b..c6d8d1a 100644 --- a/src/ConstraintViolationException.php +++ b/src/ConstraintViolationException.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace TheCodingMachine\Graphqlite\Validator; +namespace TheCodingMachine\GraphQLite\Validator; use Exception; use Symfony\Component\Validator\ConstraintViolationInterface; diff --git a/src/Mappers/Parameters/AssertParameterMiddleware.php b/src/Mappers/Parameters/AssertParameterMiddleware.php index 7a7a888..7fe51d8 100644 --- a/src/Mappers/Parameters/AssertParameterMiddleware.php +++ b/src/Mappers/Parameters/AssertParameterMiddleware.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace TheCodingMachine\Graphqlite\Validator\Mappers\Parameters; +namespace TheCodingMachine\GraphQLite\Validator\Mappers\Parameters; use phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\Type; @@ -15,7 +15,7 @@ use TheCodingMachine\GraphQLite\Mappers\Parameters\ParameterMiddlewareInterface; use TheCodingMachine\GraphQLite\Parameters\InputTypeParameterInterface; use TheCodingMachine\GraphQLite\Parameters\ParameterInterface; -use TheCodingMachine\Graphqlite\Validator\Annotations\Assertion; +use TheCodingMachine\GraphQLite\Validator\Annotations\Assertion; use function array_map; use function array_merge; diff --git a/src/Mappers/Parameters/InvalidAssertionAnnotationException.php b/src/Mappers/Parameters/InvalidAssertionAnnotationException.php index 5344363..9ab7404 100644 --- a/src/Mappers/Parameters/InvalidAssertionAnnotationException.php +++ b/src/Mappers/Parameters/InvalidAssertionAnnotationException.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace TheCodingMachine\Graphqlite\Validator\Mappers\Parameters; +namespace TheCodingMachine\GraphQLite\Validator\Mappers\Parameters; use Exception; use ReflectionParameter; diff --git a/src/Mappers/Parameters/ParameterValidator.php b/src/Mappers/Parameters/ParameterValidator.php index 327f9e1..b893a6f 100644 --- a/src/Mappers/Parameters/ParameterValidator.php +++ b/src/Mappers/Parameters/ParameterValidator.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace TheCodingMachine\Graphqlite\Validator\Mappers\Parameters; +namespace TheCodingMachine\GraphQLite\Validator\Mappers\Parameters; use GraphQL\Type\Definition\InputType; use GraphQL\Type\Definition\ResolveInfo; @@ -12,7 +12,7 @@ use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Contracts\Translation\TranslatorInterface; use TheCodingMachine\GraphQLite\Parameters\InputTypeParameterInterface; -use TheCodingMachine\Graphqlite\Validator\ValidationFailedException; +use TheCodingMachine\GraphQLite\Validator\ValidationFailedException; class ParameterValidator implements InputTypeParameterInterface { diff --git a/src/ValidationFailedException.php b/src/ValidationFailedException.php index 0abb76f..4c123af 100644 --- a/src/ValidationFailedException.php +++ b/src/ValidationFailedException.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace TheCodingMachine\Graphqlite\Validator; +namespace TheCodingMachine\GraphQLite\Validator; use GraphQL\Error\ClientAware; use InvalidArgumentException; diff --git a/tests/Annotations/AssertionTest.php b/tests/Annotations/AssertionTest.php index f24872b..58a17a6 100644 --- a/tests/Annotations/AssertionTest.php +++ b/tests/Annotations/AssertionTest.php @@ -1,6 +1,6 @@ addControllerNamespace('TheCodingMachine\Graphqlite\Validator\Fixtures\Controllers'); - $schemaFactory->addTypeNamespace('TheCodingMachine\Graphqlite\Validator\Fixtures\Types'); + $schemaFactory->addControllerNamespace('TheCodingMachine\GraphQLite\Validator\Fixtures\Controllers'); + $schemaFactory->addTypeNamespace('TheCodingMachine\GraphQLite\Validator\Fixtures\Types'); $schemaFactory->addParameterMiddleware(new AssertParameterMiddleware(new ContainerConstraintValidatorFactory($container), $container->get(ValidatorInterface::class), $container->get(TranslatorInterface::class))); return $schemaFactory; @@ -162,11 +162,11 @@ public function testEndToEndAssert(): void public function testException(): void { $schemaFactory = $this->getSchemaFactory(); - $schemaFactory->addControllerNamespace('TheCodingMachine\Graphqlite\Validator\Fixtures\InvalidControllers'); + $schemaFactory->addControllerNamespace('TheCodingMachine\GraphQLite\Validator\Fixtures\InvalidControllers'); $schema = $schemaFactory->createSchema(); $this->expectException(InvalidAssertionAnnotationException::class); - $this->expectExceptionMessage('In method TheCodingMachine\Graphqlite\Validator\Fixtures\InvalidControllers\InvalidController::invalid(), the @Assert annotation is targeting parameter "$resolveInfo". You cannot target this parameter because it is not part of the GraphQL Input type. You can only assert parameters coming from the end user.'); + $this->expectExceptionMessage('In method TheCodingMachine\GraphQLite\Validator\Fixtures\InvalidControllers\InvalidController::invalid(), the @Assert annotation is targeting parameter "$resolveInfo". You cannot target this parameter because it is not part of the GraphQL Input type. You can only assert parameters coming from the end user.'); $schema->validate(); } } \ No newline at end of file diff --git a/tests/ValidationFailedExceptionTest.php b/tests/ValidationFailedExceptionTest.php index 35b5efe..ff4882d 100644 --- a/tests/ValidationFailedExceptionTest.php +++ b/tests/ValidationFailedExceptionTest.php @@ -1,6 +1,6 @@ Date: Thu, 28 Oct 2021 16:35:55 +0200 Subject: [PATCH 02/10] Remove dead class copied from 'thecodingmachine/graphqlite-bundle' --- GraphqliteBundle.php | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 GraphqliteBundle.php diff --git a/GraphqliteBundle.php b/GraphqliteBundle.php deleted file mode 100644 index e584bbe..0000000 --- a/GraphqliteBundle.php +++ /dev/null @@ -1,21 +0,0 @@ -addCompilerPass(new GraphqliteCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION); - $container->addCompilerPass(new OverblogGraphiQLEndpointWiringPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -1); - } -} From 2da130aadcefd2d1366e0a5083a09b7379983256 Mon Sep 17 00:00:00 2001 From: Dorian Savina Date: Thu, 28 Oct 2021 12:13:36 +0200 Subject: [PATCH 03/10] [dev][vendor] Upgrade 'doctrine/coding-standard' to ^9.0 - Disable "mixed" type hint for backward compatibility --- composer.json | 2 +- phpcs.xml.dist | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 896faf6..71e24fe 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "phpstan/phpstan": "^0.12.14", "php-coveralls/php-coveralls": "^2.1.0", "symfony/translation": "^4", - "doctrine/coding-standard": "^7.0" + "doctrine/coding-standard": "^9.0" }, "scripts": { "phpstan": "phpstan analyse src/ -c phpstan.neon --level=7 --no-progress", diff --git a/phpcs.xml.dist b/phpcs.xml.dist index a5a0885..7f81a06 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -49,4 +49,17 @@ + + + + + + + + + + + + + From 1b94f23822349f7d5f7b751422855ef957fef772 Mon Sep 17 00:00:00 2001 From: Dorian Savina Date: Thu, 28 Oct 2021 13:00:20 +0200 Subject: [PATCH 04/10] [fix][vendor] Contracts only available since Symfony 4.2 (use of 'Symfony\Contracts\Translation\TranslatorInterface') --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 71e24fe..8a68214 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "require" : { "php" : ">=7.2", "thecodingmachine/graphqlite" : "^4.1", - "symfony/validator": "^4 | ^5", + "symfony/validator": "^4.2 | ^5", "doctrine/annotations": "^1.6" }, "require-dev": { From 40c7ab49d6a471c0809dadad8740c8a7ad84aa7b Mon Sep 17 00:00:00 2001 From: Dorian Savina Date: Thu, 28 Oct 2021 12:21:35 +0200 Subject: [PATCH 05/10] [vendor] Upgrade 'thecodingmachine/graphqlite' to ^5.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8a68214..c48c4e1 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ ], "require" : { "php" : ">=7.2", - "thecodingmachine/graphqlite" : "^4.1", + "thecodingmachine/graphqlite" : "^5.0", "symfony/validator": "^4.2 | ^5", "doctrine/annotations": "^1.6" }, From 30440888a39075a097cd6e79b606109ea05f83a4 Mon Sep 17 00:00:00 2001 From: Dorian Savina Date: Thu, 28 Oct 2021 13:41:34 +0200 Subject: [PATCH 06/10] [ci] Update Travis configuration (PHP 8.0 support) --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7676be5..182f716 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,20 +15,20 @@ matrix: include: # Test the latest stable release - php: 7.2 - - php: 7.4 + - php: 8.0 env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text" # Test LTS versions. - - php: 7.4 + - php: 8.0 env: DEPENDENCIES="symfony/lts:^4" # Latest commit to master - - php: 7.4 + - php: 8.0 env: STABILITY="dev" allow_failures: # Minimum supported dependencies with the latest and oldest PHP version - - php: 7.4 + - php: 8.0 env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors" - php: 7.2 env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors" From 9a0142e09bc465b896567b0ca62d1b848f2fea6d Mon Sep 17 00:00:00 2001 From: Dorian Savina Date: Thu, 28 Oct 2021 12:26:30 +0200 Subject: [PATCH 07/10] [codestyle] Fix codestyles (missing newline, superfluous space) --- src/Annotations/Assertion.php | 3 ++- src/Mappers/Parameters/AssertParameterMiddleware.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Annotations/Assertion.php b/src/Annotations/Assertion.php index 3220c53..6d1f87d 100644 --- a/src/Annotations/Assertion.php +++ b/src/Annotations/Assertion.php @@ -7,6 +7,7 @@ use BadMethodCallException; use Symfony\Component\Validator\Constraint; use TheCodingMachine\GraphQLite\Annotations\ParameterAnnotationInterface; + use function is_array; use function ltrim; @@ -41,7 +42,7 @@ public function __construct(array $values) } $this->for = ltrim($values['for'], '$'); - $this->constraint = is_array($values['constraint']) ? $values['constraint'] : [ $values['constraint'] ]; + $this->constraint = is_array($values['constraint']) ? $values['constraint'] : [$values['constraint']]; } public function getTarget(): string diff --git a/src/Mappers/Parameters/AssertParameterMiddleware.php b/src/Mappers/Parameters/AssertParameterMiddleware.php index 7fe51d8..75150b0 100644 --- a/src/Mappers/Parameters/AssertParameterMiddleware.php +++ b/src/Mappers/Parameters/AssertParameterMiddleware.php @@ -16,6 +16,7 @@ use TheCodingMachine\GraphQLite\Parameters\InputTypeParameterInterface; use TheCodingMachine\GraphQLite\Parameters\ParameterInterface; use TheCodingMachine\GraphQLite\Validator\Annotations\Assertion; + use function array_map; use function array_merge; From 2469b3b429da6657e79cfff5708e4ce5d0a0a22d Mon Sep 17 00:00:00 2001 From: Dorian Savina Date: Thu, 28 Oct 2021 12:52:59 +0200 Subject: [PATCH 08/10] [fix] Handle possibly empty strings instead of null --- src/ConstraintViolationException.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ConstraintViolationException.php b/src/ConstraintViolationException.php index c6d8d1a..e2e1b84 100644 --- a/src/ConstraintViolationException.php +++ b/src/ConstraintViolationException.php @@ -46,12 +46,12 @@ public function getExtensions(): array { $extensions = []; $code = $this->violation->getCode(); - if ($code !== null) { + if (! empty($code)) { $extensions['code'] = $code; } $propertyPath = $this->violation->getPropertyPath(); - if ($propertyPath !== null) { + if (! empty($propertyPath)) { $extensions['field'] = $propertyPath; } From d0aa86f3f1f7354118388617351604c7256b7450 Mon Sep 17 00:00:00 2001 From: Dorian Savina Date: Thu, 28 Oct 2021 12:53:57 +0200 Subject: [PATCH 09/10] [fix][tests] Update imports - Remove unused imports - Class 'GraphQL\Error\Debug' externally renamed to 'DebugFlag' --- tests/ConstraintValidationExceptionTest.php | 1 - tests/IntegrationTest.php | 16 +++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/ConstraintValidationExceptionTest.php b/tests/ConstraintValidationExceptionTest.php index e4b3960..cc89493 100644 --- a/tests/ConstraintValidationExceptionTest.php +++ b/tests/ConstraintValidationExceptionTest.php @@ -4,7 +4,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Validator\ConstraintViolation; -use Symfony\Component\Validator\ConstraintViolationList; class ConstraintValidationExceptionTest extends TestCase { diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 0266694..3da5351 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -5,31 +5,25 @@ use Doctrine\Common\Annotations\AnnotationReader; -use GraphQL\Error\Debug; +use GraphQL\Error\DebugFlag; use GraphQL\GraphQL; use GraphQL\Type\Schema; use Mouf\Picotainer\Picotainer; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use Symfony\Component\Cache\Adapter\ArrayAdapter; -use Symfony\Component\Cache\Adapter\Psr16Adapter; use Symfony\Component\Cache\Psr16Cache; -use Symfony\Component\Cache\Simple\ArrayCache; use Symfony\Component\Translation\Translator; use Symfony\Component\Validator\ContainerConstraintValidatorFactory; use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Component\Validator\ValidatorBuilder; use Symfony\Contracts\Translation\TranslatorInterface; use TheCodingMachine\GraphQLite\Containers\BasicAutoWiringContainer; -use TheCodingMachine\GraphQLite\Containers\EmptyContainer; use TheCodingMachine\GraphQLite\Exceptions\WebonyxErrorHandler; use TheCodingMachine\GraphQLite\SchemaFactory; use TheCodingMachine\GraphQLite\Validator\Fixtures\Controllers\UserController; use TheCodingMachine\GraphQLite\Validator\Mappers\Parameters\AssertParameterMiddleware; use TheCodingMachine\GraphQLite\Validator\Mappers\Parameters\InvalidAssertionAnnotationException; -use function var_dump; -use function var_export; -use const JSON_PRETTY_PRINT; class IntegrationTest extends TestCase { @@ -83,7 +77,7 @@ public function testEndToEndThrowException(): void $result->setErrorsHandler([WebonyxErrorHandler::class, 'errorHandler']); $result->setErrorFormatter([WebonyxErrorHandler::class, 'errorFormatter']); - $errors = $result->toArray(Debug::RETHROW_UNSAFE_EXCEPTIONS)['errors']; + $errors = $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors']; $this->assertSame('The email \'"foofgdjkerbrtehrthjker.com"\' is not a valid email.', $errors[0]['message']); $this->assertSame('email', $errors[0]['extensions']['field']); $this->assertSame('Validate', $errors[0]['extensions']['category']); @@ -112,7 +106,7 @@ public function testEndToEndAssert(): void $result->setErrorsHandler([WebonyxErrorHandler::class, 'errorHandler']); $result->setErrorFormatter([WebonyxErrorHandler::class, 'errorFormatter']); - $errors = $result->toArray(Debug::RETHROW_UNSAFE_EXCEPTIONS)['errors']; + $errors = $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors']; // TODO: find why message is not in French... $this->assertSame('This value is not a valid email address.', $errors[0]['message']); @@ -135,7 +129,7 @@ public function testEndToEndAssert(): void $result->setErrorsHandler([WebonyxErrorHandler::class, 'errorHandler']); $result->setErrorFormatter([WebonyxErrorHandler::class, 'errorFormatter']); - $data = $result->toArray(Debug::RETHROW_UNSAFE_EXCEPTIONS)['data']; + $data = $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['data']; $this->assertSame('valid@valid.com', $data['findByMail']['email']); // Test default parameter @@ -154,7 +148,7 @@ public function testEndToEndAssert(): void $result->setErrorsHandler([WebonyxErrorHandler::class, 'errorHandler']); $result->setErrorFormatter([WebonyxErrorHandler::class, 'errorFormatter']); - $data = $result->toArray(Debug::RETHROW_UNSAFE_EXCEPTIONS)['data']; + $data = $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['data']; $this->assertSame('a@a.com', $data['findByMail']['email']); } From a89df7654fbb91cc1bdbe6dc724b016486527a3a Mon Sep 17 00:00:00 2001 From: Dorian Savina Date: Thu, 28 Oct 2021 17:22:08 +0200 Subject: [PATCH 10/10] [version] Bump branch alias to 5.0.x --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c48c4e1..2e18e0a 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,7 @@ }, "extra": { "branch-alias": { - "dev-master": "4.1.x-dev" + "dev-master": "5.0.x-dev" } }, "minimum-stability": "dev",