Skip to content

test(graphql): odm fixture #6100 #6168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions tests/Fixtures/TestBundle/Document/OptionalRequiredDummy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?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\Document;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GraphQl\Mutation;
use ApiPlatform\Metadata\GraphQl\Query;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
* OptionalRequiredDummy. Used to test GraphQL Schema generation for nullable embedded relations.
*/
#[ApiResource(
graphQlOperations: [
new Query(name: 'item_query'),
new Mutation(name: 'update', normalizationContext: ['groups' => ['chicago', 'fakemanytomany']], denormalizationContext: ['groups' => ['friends']]),
],
)]
#[ODM\Document]
class OptionalRequiredDummy
{
#[ApiProperty(writable: false)]
#[ODM\Id(strategy: 'INCREMENT', type: 'int')]
#[Groups(['chicago', 'friends'])]
private $id;

#[ODM\ReferenceOne(targetDocument: ThirdLevel::class, inversedBy: 'thirdLevel', nullable: true, storeAs: 'id')]
#[Groups(['barcelona', 'chicago', 'friends'])]
public ?ThirdLevel $thirdLevel = null;

#[ODM\ReferenceOne(targetDocument: ThirdLevel::class, inversedBy: 'thirdLevelRequired', nullable: true, storeAs: 'id')]
#[ApiProperty(required: true)]
#[Groups(['barcelona', 'chicago', 'friends'])]
public ThirdLevel $thirdLevelRequired;

#[ODM\ReferenceMany(targetDocument: RelatedToDummyFriend::class, mappedBy: 'relatedDummy')]
#[Groups(['fakemanytomany', 'friends'])]
public Collection|iterable $relatedToDummyFriend;

public function __construct()
{
$this->relatedToDummyFriend = new ArrayCollection();
}

public function getId()
{
return $this->id;
}

public function setId($id): void
{
$this->id = $id;
}

public function getThirdLevel(): ?ThirdLevel
{
return $this->thirdLevel;
}

public function setThirdLevel(?ThirdLevel $thirdLevel = null): void
{
$this->thirdLevel = $thirdLevel;
}

public function getThirdLevelRequired(): ThirdLevel
{
return $this->thirdLevelRequired;
}

public function setThirdLevelRequired(ThirdLevel $thirdLevelRequired): void
{
$this->thirdLevelRequired = $thirdLevelRequired;
}

/**
* Get relatedToDummyFriend.
*/
public function getRelatedToDummyFriend(): Collection|iterable
{
return $this->relatedToDummyFriend;
}

/**
* Set relatedToDummyFriend.
*
* @param RelatedToDummyFriend $relatedToDummyFriend the value to set
*/
public function addRelatedToDummyFriend(RelatedToDummyFriend $relatedToDummyFriend): void
{
$this->relatedToDummyFriend->add($relatedToDummyFriend);
}

public function __toString(): string
{
return (string) $this->getId();
}
}