-
-
Notifications
You must be signed in to change notification settings - Fork 868
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(graphql): link relations requires the property (#5169)
Co-authored-by: Alan Poulain <contact@alanpoulain.eu>
- Loading branch information
1 parent
2604044
commit 3d3c2c7
Showing
11 changed files
with
387 additions
and
12 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
79 changes: 79 additions & 0 deletions
79
tests/Fixtures/TestBundle/Document/MultiRelationsDummy.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,79 @@ | ||
<?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\Tests\Fixtures\TestBundle\Document; | ||
|
||
use ApiPlatform\Metadata\ApiResource; | ||
use ApiPlatform\Metadata\GraphQl\Query; | ||
use ApiPlatform\Metadata\GraphQl\QueryCollection; | ||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; | ||
|
||
/** | ||
* Dummy using different kind of relations to the same resource. | ||
* | ||
* @author Thomas Helmrich <thomas@gigabit.de> | ||
*/ | ||
#[ApiResource(graphQlOperations: [new QueryCollection(), new Query()])] | ||
#[ODM\Document] | ||
class MultiRelationsDummy | ||
{ | ||
#[ODM\Id(strategy: 'INCREMENT', type: 'int')] | ||
private ?int $id = null; | ||
|
||
#[ODM\Field(type: 'string')] | ||
public string $name; | ||
|
||
#[ODM\ReferenceOne(targetDocument: MultiRelationsRelatedDummy::class, storeAs: 'id', nullable: true)] | ||
public ?MultiRelationsRelatedDummy $manyToOneRelation = null; | ||
|
||
/** @var Collection<int, MultiRelationsRelatedDummy> */ | ||
#[ODM\ReferenceMany(targetDocument: MultiRelationsRelatedDummy::class, storeAs: 'id', nullable: true)] | ||
public Collection $manyToManyRelations; | ||
|
||
/** @var Collection<int, MultiRelationsRelatedDummy> */ | ||
#[ODM\ReferenceMany(targetDocument: MultiRelationsRelatedDummy::class, mappedBy: 'oneToManyRelation', storeAs: 'id')] | ||
public Collection $oneToManyRelations; | ||
|
||
public function __construct() | ||
{ | ||
$this->manyToManyRelations = new ArrayCollection(); | ||
$this->oneToManyRelations = new ArrayCollection(); | ||
} | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getManyToOneRelation(): ?MultiRelationsRelatedDummy | ||
{ | ||
return $this->manyToOneRelation; | ||
} | ||
|
||
public function setManyToOneRelation(?MultiRelationsRelatedDummy $relatedMultiUsedDummy): void | ||
{ | ||
$this->manyToOneRelation = $relatedMultiUsedDummy; | ||
} | ||
|
||
public function addManyToManyRelation(MultiRelationsRelatedDummy $relatedMultiUsedDummy): void | ||
{ | ||
$this->manyToManyRelations->add($relatedMultiUsedDummy); | ||
} | ||
|
||
public function addOneToManyRelation(MultiRelationsRelatedDummy $relatedMultiUsedDummy): void | ||
{ | ||
$this->oneToManyRelations->add($relatedMultiUsedDummy); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
tests/Fixtures/TestBundle/Document/MultiRelationsRelatedDummy.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,53 @@ | ||
<?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\Tests\Fixtures\TestBundle\Document; | ||
|
||
use ApiPlatform\Metadata\ApiResource; | ||
use ApiPlatform\Metadata\GraphQl\Query; | ||
use ApiPlatform\Metadata\GraphQl\QueryCollection; | ||
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; | ||
|
||
/** | ||
* Dummy used in different kind of relations in the same resource. | ||
* | ||
* @author Thomas Helmrich <thomas@gigabit.de> | ||
*/ | ||
#[ApiResource(graphQlOperations: [new QueryCollection(), new Query()])] | ||
#[ODM\Document] | ||
class MultiRelationsRelatedDummy | ||
{ | ||
#[ODM\Id(strategy: 'INCREMENT', type: 'int')] | ||
private ?int $id = null; | ||
|
||
#[ODM\Field(type: 'string', nullable: true)] | ||
public ?string $name; | ||
|
||
#[ODM\ReferenceOne(targetDocument: MultiRelationsDummy::class, inversedBy: 'oneToManyRelations', nullable: true, storeAs: 'id')] | ||
private ?MultiRelationsDummy $oneToManyRelation; | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getOneToManyRelation(): ?MultiRelationsDummy | ||
{ | ||
return $this->oneToManyRelation; | ||
} | ||
|
||
public function setOneToManyRelation(?MultiRelationsDummy $oneToManyRelation): void | ||
{ | ||
$this->oneToManyRelation = $oneToManyRelation; | ||
} | ||
} |
Oops, something went wrong.