-
-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(graphql): output creates its own type in TypeBuilder (#4766)
- Loading branch information
1 parent
d876e66
commit 4fe0821
Showing
12 changed files
with
223 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
tests/Fixtures/TestBundle/DataTransformer/DummyCustomMutationDtoDataTransformer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* 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\DataTransformer; | ||
|
||
use ApiPlatform\Core\DataTransformer\DataTransformerInterface; | ||
use ApiPlatform\Tests\Fixtures\TestBundle\Document\DummyCustomMutation as DummyCustomMutationDocument; | ||
use ApiPlatform\Tests\Fixtures\TestBundle\Dto\OutputDto; | ||
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyCustomMutation; | ||
|
||
final class DummyCustomMutationDtoDataTransformer implements DataTransformerInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @return object | ||
*/ | ||
public function transform($object, string $to, array $context = []) | ||
{ | ||
if ($object instanceof \Traversable) { | ||
foreach ($object as &$value) { | ||
$value = $this->doTransformation($value); | ||
} | ||
|
||
return $object; | ||
} | ||
|
||
return $this->doTransformation($object); | ||
} | ||
|
||
private function doTransformation($object): OutputDto | ||
{ | ||
$output = new OutputDto(); | ||
$output->baz = 98; | ||
$output->bat = $object->getOperandA(); | ||
|
||
return $output; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supportsTransformation($object, string $to, array $context = []): bool | ||
{ | ||
if ($object instanceof \IteratorAggregate) { | ||
$iterator = $object->getIterator(); | ||
if ($iterator instanceof \Iterator) { | ||
$object = $iterator->current(); | ||
} | ||
} | ||
|
||
return ($object instanceof DummyCustomMutation || $object instanceof DummyCustomMutationDocument) && OutputDto::class === $to; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
tests/Fixtures/TestBundle/DataTransformer/DummyCustomQueryDtoDataTransformer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* 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\DataTransformer; | ||
|
||
use ApiPlatform\Core\DataTransformer\DataTransformerInterface; | ||
use ApiPlatform\Tests\Fixtures\TestBundle\Document\DummyCustomQuery as DummyCustomQueryDocument; | ||
use ApiPlatform\Tests\Fixtures\TestBundle\Dto\OutputDto; | ||
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyCustomQuery; | ||
|
||
final class DummyCustomQueryDtoDataTransformer implements DataTransformerInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @return object | ||
*/ | ||
public function transform($object, string $to, array $context = []) | ||
{ | ||
if ($object instanceof \Traversable) { | ||
foreach ($object as &$value) { | ||
$value = $this->doTransformation($value); | ||
} | ||
|
||
return $object; | ||
} | ||
|
||
return $this->doTransformation($object); | ||
} | ||
|
||
private function doTransformation($object): OutputDto | ||
{ | ||
$output = new OutputDto(); | ||
$output->baz = 46; | ||
$output->bat = $object->message; | ||
|
||
return $output; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supportsTransformation($object, string $to, array $context = []): bool | ||
{ | ||
if ($object instanceof \IteratorAggregate) { | ||
$iterator = $object->getIterator(); | ||
if ($iterator instanceof \Iterator) { | ||
$object = $iterator->current(); | ||
} | ||
} | ||
|
||
return ($object instanceof DummyCustomQuery || $object instanceof DummyCustomQueryDocument) && OutputDto::class === $to; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters