|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the API Platform project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <dunglas@gmail.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace ApiPlatform\Tests\Functional\GraphQl; |
| 15 | + |
| 16 | +use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; |
| 17 | +use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue2754\Sum; |
| 18 | +use ApiPlatform\Tests\SetupClassResourcesTrait; |
| 19 | + |
| 20 | +/** |
| 21 | + * A custom GraphQL mutation declaring an explicit output DTO must expose the |
| 22 | + * output DTO's fields on its payload type, not the resource's fields. |
| 23 | + * |
| 24 | + * @see https://github.com/api-platform/core/issues/2754 |
| 25 | + */ |
| 26 | +final class Issue2754Test extends ApiTestCase |
| 27 | +{ |
| 28 | + use SetupClassResourcesTrait; |
| 29 | + |
| 30 | + protected static ?bool $alwaysBootKernel = false; |
| 31 | + |
| 32 | + /** |
| 33 | + * @return class-string[] |
| 34 | + */ |
| 35 | + public static function getResources(): array |
| 36 | + { |
| 37 | + return [Sum::class]; |
| 38 | + } |
| 39 | + |
| 40 | + public function testCustomMutationHonorsOutputClassFields(): void |
| 41 | + { |
| 42 | + $response = self::createClient()->request('POST', '/graphql', ['json' => [ |
| 43 | + 'query' => <<<'GRAPHQL' |
| 44 | +mutation { |
| 45 | + sumSum(input: {operandA: 2, operandB: 3}) { |
| 46 | + sum { |
| 47 | + sum |
| 48 | + } |
| 49 | + } |
| 50 | +} |
| 51 | +GRAPHQL, |
| 52 | + ]]); |
| 53 | + |
| 54 | + $this->assertResponseIsSuccessful(); |
| 55 | + $json = $response->toArray(false); |
| 56 | + $this->assertArrayNotHasKey('errors', $json, json_encode($json['errors'] ?? null)); |
| 57 | + $this->assertSame(5, $json['data']['sumSum']['sum']['sum']); |
| 58 | + } |
| 59 | +} |
0 commit comments