diff --git a/features/graphql/mutation.feature b/features/graphql/mutation.feature index 63f46bb7096..e26332bb632 100644 --- a/features/graphql/mutation.feature +++ b/features/graphql/mutation.feature @@ -1034,3 +1034,20 @@ Feature: GraphQL mutation support """ Then the response status code should be 200 And the JSON node "data.uploadMultipleMediaObject.mediaObject.contentUrl" should be equal to "test.gif" + + @!mongodb + Scenario: Mutation should run before validation + When I send the following GraphQL request: + """ + mutation { + createActivityLog(input: {name: ""}) { + activityLog { + name + } + } + } + """ + Then the response status code should be 200 + And the response should be in JSON + And the header "Content-Type" should be equal to "application/json" + And the JSON node "data.createActivityLog.activityLog.name" should be equal to "hi" diff --git a/src/Symfony/Bundle/Resources/config/graphql.xml b/src/Symfony/Bundle/Resources/config/graphql.xml index 14bf60b8405..e2a4556a437 100644 --- a/src/Symfony/Bundle/Resources/config/graphql.xml +++ b/src/Symfony/Bundle/Resources/config/graphql.xml @@ -158,8 +158,8 @@ - - + + diff --git a/tests/Fixtures/TestBundle/ApiResource/Issue6354/ActivityLog.php b/tests/Fixtures/TestBundle/ApiResource/Issue6354/ActivityLog.php new file mode 100644 index 00000000000..bdd0bdf87b8 --- /dev/null +++ b/tests/Fixtures/TestBundle/ApiResource/Issue6354/ActivityLog.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue6354; + +use ApiPlatform\Metadata\ApiResource; +use ApiPlatform\Metadata\GraphQl\Mutation; +use Symfony\Component\Validator\Constraints\NotBlank; + +#[ApiResource( + graphQlOperations: [ + new Mutation( + resolver: 'app.graphql.mutation_resolver.activity_log', + name: 'create' + ), + ] +)] +class ActivityLog +{ + public function __construct(#[NotBlank()] public ?string $name = null) + { + } +} diff --git a/tests/Fixtures/TestBundle/ApiResource/Issue6354/CreateActivityLogResolver.php b/tests/Fixtures/TestBundle/ApiResource/Issue6354/CreateActivityLogResolver.php new file mode 100644 index 00000000000..4784d81ecb0 --- /dev/null +++ b/tests/Fixtures/TestBundle/ApiResource/Issue6354/CreateActivityLogResolver.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue6354; + +use ApiPlatform\GraphQl\Resolver\MutationResolverInterface; + +class CreateActivityLogResolver implements MutationResolverInterface +{ + /** + * @param object|null $item + * @param mixed[] $context + */ + public function __invoke($item, array $context): ActivityLog + { + if (!$item instanceof ActivityLog) { + throw new \InvalidArgumentException('Missing input of type ActivityLog'); + } + + $item->name = 'hi'; + + return $item; + } +} diff --git a/tests/Fixtures/app/config/config_common.yml b/tests/Fixtures/app/config/config_common.yml index d9edd6f3308..0807d46806d 100644 --- a/tests/Fixtures/app/config/config_common.yml +++ b/tests/Fixtures/app/config/config_common.yml @@ -455,3 +455,8 @@ services: tags: - name: 'api_platform.parameter_provider' key: 'ApiPlatform\Tests\Fixtures\TestBundle\Parameter\CustomGroupParameterProvider' + + app.graphql.mutation_resolver.activity_log: + class: 'ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue6354\CreateActivityLogResolver' + tags: + - name: 'api_platform.graphql.resolver'