-
-
Notifications
You must be signed in to change notification settings - Fork 848
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support DTO class on GraphQL (#2427)
* Support DTO class on GraphQL * Fix review * Add Behat tests * Fix CS * Fix left over * Handle false value as input_class/output_class * Fix review * Optimize imports * Revert optimize imports * Fix review
- Loading branch information
1 parent
009e86a
commit c3e631e
Showing
10 changed files
with
460 additions
and
20 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
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
61 changes: 61 additions & 0 deletions
61
tests/Fixtures/TestBundle/DataPersister/DummyDtoNoOutputDataPersister.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,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* 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\Core\Tests\Fixtures\TestBundle\DataPersister; | ||
|
||
use ApiPlatform\Core\DataPersister\DataPersisterInterface; | ||
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyDtoNoOutput; | ||
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\InputDto; | ||
use Doctrine\Common\Persistence\ManagerRegistry; | ||
|
||
class DummyDtoNoOutputDataPersister implements DataPersisterInterface | ||
{ | ||
private $registry; | ||
|
||
public function __construct(ManagerRegistry $registry) | ||
{ | ||
$this->registry = $registry; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supports($data): bool | ||
{ | ||
return $data instanceof InputDto; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function persist($data) | ||
{ | ||
$output = new DummyDtoNoOutput(); | ||
$output->lorem = $data->foo; | ||
$output->ipsum = (string) $data->bar; | ||
|
||
$em = $this->registry->getManagerForClass(DummyDtoNoOutput::class); | ||
$em->persist($output); | ||
$em->flush(); | ||
|
||
return $output; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function remove($data) | ||
{ | ||
return null; | ||
} | ||
} |
Oops, something went wrong.