Skip to content

Commit

Permalink
chore(doctrine): ignore mongodb embeded #6038
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Jan 16, 2024
1 parent 8577e89 commit ad9cc6f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 10 deletions.
49 changes: 49 additions & 0 deletions features/graphql/query.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,55 @@ Feature: GraphQL query support

@createSchema
Scenario: Retrieve an item with different relations to the same resource
Given there are 2 multiRelationsDummy objects having each a manyToOneRelation, 2 manyToManyRelations, 3 oneToManyRelations and 4 embeddedRelations
When I send the following GraphQL request:
"""
{
multiRelationsDummy(id: "/multi_relations_dummies/2") {
id
name
manyToOneRelation {
id
name
}
manyToManyRelations {
edges{
node {
id
name
}
}
}
oneToManyRelations {
edges{
node {
id
name
}
}
}
}
}
"""
Then print last JSON response
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.multiRelationsDummy.id" should be equal to "/multi_relations_dummies/2"
And the JSON node "data.multiRelationsDummy.name" should be equal to "Dummy #2"
And the JSON node "data.multiRelationsDummy.manyToOneRelation.id" should not be null
And the JSON node "data.multiRelationsDummy.manyToOneRelation.name" should be equal to "RelatedManyToOneDummy #2"
And the JSON node "data.multiRelationsDummy.manyToManyRelations.edges" should have 2 element
And the JSON node "data.multiRelationsDummy.manyToManyRelations.edges[1].node.id" should not be null
And the JSON node "data.multiRelationsDummy.manyToManyRelations.edges[0].node.name" should match "#RelatedManyToManyDummy(1|2)2#"
And the JSON node "data.multiRelationsDummy.manyToManyRelations.edges[1].node.name" should match "#RelatedManyToManyDummy(1|2)2#"
And the JSON node "data.multiRelationsDummy.oneToManyRelations.edges" should have 3 element
And the JSON node "data.multiRelationsDummy.oneToManyRelations.edges[1].node.id" should not be null
And the JSON node "data.multiRelationsDummy.oneToManyRelations.edges[0].node.name" should match "#RelatedOneToManyDummy(1|3)2#"
And the JSON node "data.multiRelationsDummy.oneToManyRelations.edges[2].node.name" should match "#RelatedOneToManyDummy(1|3)2#"

@createSchema @!mongodb
Scenario: Retrieve embedded collections
Given there are 2 multiRelationsDummy objects having each a manyToOneRelation, 2 manyToManyRelations, 3 oneToManyRelations and 4 embeddedRelations
When I send the following GraphQL request:
"""
Expand Down
20 changes: 10 additions & 10 deletions tests/Fixtures/TestBundle/Document/MultiRelationsDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ class MultiRelationsDummy
#[ODM\ReferenceMany(targetDocument: MultiRelationsRelatedDummy::class, mappedBy: 'oneToManyRelation', storeAs: 'id')]
public Collection $oneToManyRelations;

/** @var array<MultiRelationsNested> */
/** @var Collection<MultiRelationsNested> */
#[ODM\EmbedMany]
private array $nestedCollection;
private Collection $nestedCollection;

/** @var array<MultiRelationsNestedPaginated> */
/** @var Collection<MultiRelationsNestedPaginated> */
#[ODM\EmbedMany]
private array $nestedPaginatedCollection;
private Collection $nestedPaginatedCollection;

public function __construct()
{
$this->manyToManyRelations = new ArrayCollection();
$this->oneToManyRelations = new ArrayCollection();
$this->nestedCollection = [];
$this->nestedPaginatedCollection = [];
$this->nestedCollection = new ArrayCollection();
$this->nestedPaginatedCollection = new ArrayCollection();
}

public function getId(): ?int
Expand Down Expand Up @@ -89,24 +89,24 @@ public function addOneToManyRelation(MultiRelationsRelatedDummy $relatedMultiUse

public function getNestedCollection(): Collection
{
return new ArrayCollection($this->nestedCollection);
return $this->nestedCollection;
}

public function setNestedCollection(Collection $nestedCollection): self
{
$this->nestedCollection = $nestedCollection->toArray();
$this->nestedCollection = $nestedCollection;

return $this;
}

public function getNestedPaginatedCollection(): Collection
{
return new ArrayCollection($this->nestedPaginatedCollection);
return $this->nestedPaginatedCollection;
}

public function setNestedPaginatedCollection(Collection $nestedPaginatedCollection): self
{
$this->nestedPaginatedCollection = $nestedPaginatedCollection->toArray();
$this->nestedPaginatedCollection = $nestedPaginatedCollection;

return $this;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Fixtures/TestBundle/Document/MultiRelationsNested.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GraphQl\QueryCollection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

#[ApiResource(graphQlOperations: [new QueryCollection(paginationEnabled: false, nested: true)])]
#[ODM\EmbeddedDocument]
class MultiRelationsNested
{
#[ODM\Field(type: 'string')]
public ?string $name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GraphQl\QueryCollection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

#[ApiResource(graphQlOperations: [new QueryCollection(nested: true)])]
#[ODM\EmbeddedDocument]
class MultiRelationsNestedPaginated
{
#[ODM\Field(type: 'string')]
public ?string $name;
}

0 comments on commit ad9cc6f

Please sign in to comment.