Skip to content

Commit 7694219

Browse files
authored
test(graphql): odm fixture #6100 (#6168)
1 parent 401b658 commit 7694219

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
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\Fixtures\TestBundle\Document;
15+
16+
use ApiPlatform\Metadata\ApiProperty;
17+
use ApiPlatform\Metadata\ApiResource;
18+
use ApiPlatform\Metadata\GraphQl\Mutation;
19+
use ApiPlatform\Metadata\GraphQl\Query;
20+
use Doctrine\Common\Collections\ArrayCollection;
21+
use Doctrine\Common\Collections\Collection;
22+
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
23+
use Symfony\Component\Serializer\Annotation\Groups;
24+
25+
/**
26+
* OptionalRequiredDummy. Used to test GraphQL Schema generation for nullable embedded relations.
27+
*/
28+
#[ApiResource(
29+
graphQlOperations: [
30+
new Query(name: 'item_query'),
31+
new Mutation(name: 'update', normalizationContext: ['groups' => ['chicago', 'fakemanytomany']], denormalizationContext: ['groups' => ['friends']]),
32+
],
33+
)]
34+
#[ODM\Document]
35+
class OptionalRequiredDummy
36+
{
37+
#[ApiProperty(writable: false)]
38+
#[ODM\Id(strategy: 'INCREMENT', type: 'int')]
39+
#[Groups(['chicago', 'friends'])]
40+
private $id;
41+
42+
#[ODM\ReferenceOne(targetDocument: ThirdLevel::class, inversedBy: 'thirdLevel', nullable: true, storeAs: 'id')]
43+
#[Groups(['barcelona', 'chicago', 'friends'])]
44+
public ?ThirdLevel $thirdLevel = null;
45+
46+
#[ODM\ReferenceOne(targetDocument: ThirdLevel::class, inversedBy: 'thirdLevelRequired', nullable: true, storeAs: 'id')]
47+
#[ApiProperty(required: true)]
48+
#[Groups(['barcelona', 'chicago', 'friends'])]
49+
public ThirdLevel $thirdLevelRequired;
50+
51+
#[ODM\ReferenceMany(targetDocument: RelatedToDummyFriend::class, mappedBy: 'relatedDummy')]
52+
#[Groups(['fakemanytomany', 'friends'])]
53+
public Collection|iterable $relatedToDummyFriend;
54+
55+
public function __construct()
56+
{
57+
$this->relatedToDummyFriend = new ArrayCollection();
58+
}
59+
60+
public function getId()
61+
{
62+
return $this->id;
63+
}
64+
65+
public function setId($id): void
66+
{
67+
$this->id = $id;
68+
}
69+
70+
public function getThirdLevel(): ?ThirdLevel
71+
{
72+
return $this->thirdLevel;
73+
}
74+
75+
public function setThirdLevel(?ThirdLevel $thirdLevel = null): void
76+
{
77+
$this->thirdLevel = $thirdLevel;
78+
}
79+
80+
public function getThirdLevelRequired(): ThirdLevel
81+
{
82+
return $this->thirdLevelRequired;
83+
}
84+
85+
public function setThirdLevelRequired(ThirdLevel $thirdLevelRequired): void
86+
{
87+
$this->thirdLevelRequired = $thirdLevelRequired;
88+
}
89+
90+
/**
91+
* Get relatedToDummyFriend.
92+
*/
93+
public function getRelatedToDummyFriend(): Collection|iterable
94+
{
95+
return $this->relatedToDummyFriend;
96+
}
97+
98+
/**
99+
* Set relatedToDummyFriend.
100+
*
101+
* @param RelatedToDummyFriend $relatedToDummyFriend the value to set
102+
*/
103+
public function addRelatedToDummyFriend(RelatedToDummyFriend $relatedToDummyFriend): void
104+
{
105+
$this->relatedToDummyFriend->add($relatedToDummyFriend);
106+
}
107+
108+
public function __toString(): string
109+
{
110+
return (string) $this->getId();
111+
}
112+
}

0 commit comments

Comments
 (0)