Skip to content

Commit ad9cc6f

Browse files
committed
chore(doctrine): ignore mongodb embeded #6038
1 parent 8577e89 commit ad9cc6f

File tree

4 files changed

+65
-10
lines changed

4 files changed

+65
-10
lines changed

features/graphql/query.feature

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,55 @@ Feature: GraphQL query support
2222

2323
@createSchema
2424
Scenario: Retrieve an item with different relations to the same resource
25+
Given there are 2 multiRelationsDummy objects having each a manyToOneRelation, 2 manyToManyRelations, 3 oneToManyRelations and 4 embeddedRelations
26+
When I send the following GraphQL request:
27+
"""
28+
{
29+
multiRelationsDummy(id: "/multi_relations_dummies/2") {
30+
id
31+
name
32+
manyToOneRelation {
33+
id
34+
name
35+
}
36+
manyToManyRelations {
37+
edges{
38+
node {
39+
id
40+
name
41+
}
42+
}
43+
}
44+
oneToManyRelations {
45+
edges{
46+
node {
47+
id
48+
name
49+
}
50+
}
51+
}
52+
}
53+
}
54+
"""
55+
Then print last JSON response
56+
Then the response status code should be 200
57+
And the response should be in JSON
58+
And the header "Content-Type" should be equal to "application/json"
59+
And the JSON node "data.multiRelationsDummy.id" should be equal to "/multi_relations_dummies/2"
60+
And the JSON node "data.multiRelationsDummy.name" should be equal to "Dummy #2"
61+
And the JSON node "data.multiRelationsDummy.manyToOneRelation.id" should not be null
62+
And the JSON node "data.multiRelationsDummy.manyToOneRelation.name" should be equal to "RelatedManyToOneDummy #2"
63+
And the JSON node "data.multiRelationsDummy.manyToManyRelations.edges" should have 2 element
64+
And the JSON node "data.multiRelationsDummy.manyToManyRelations.edges[1].node.id" should not be null
65+
And the JSON node "data.multiRelationsDummy.manyToManyRelations.edges[0].node.name" should match "#RelatedManyToManyDummy(1|2)2#"
66+
And the JSON node "data.multiRelationsDummy.manyToManyRelations.edges[1].node.name" should match "#RelatedManyToManyDummy(1|2)2#"
67+
And the JSON node "data.multiRelationsDummy.oneToManyRelations.edges" should have 3 element
68+
And the JSON node "data.multiRelationsDummy.oneToManyRelations.edges[1].node.id" should not be null
69+
And the JSON node "data.multiRelationsDummy.oneToManyRelations.edges[0].node.name" should match "#RelatedOneToManyDummy(1|3)2#"
70+
And the JSON node "data.multiRelationsDummy.oneToManyRelations.edges[2].node.name" should match "#RelatedOneToManyDummy(1|3)2#"
71+
72+
@createSchema @!mongodb
73+
Scenario: Retrieve embedded collections
2574
Given there are 2 multiRelationsDummy objects having each a manyToOneRelation, 2 manyToManyRelations, 3 oneToManyRelations and 4 embeddedRelations
2675
When I send the following GraphQL request:
2776
"""

tests/Fixtures/TestBundle/Document/MultiRelationsDummy.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,20 @@ class MultiRelationsDummy
4646
#[ODM\ReferenceMany(targetDocument: MultiRelationsRelatedDummy::class, mappedBy: 'oneToManyRelation', storeAs: 'id')]
4747
public Collection $oneToManyRelations;
4848

49-
/** @var array<MultiRelationsNested> */
49+
/** @var Collection<MultiRelationsNested> */
5050
#[ODM\EmbedMany]
51-
private array $nestedCollection;
51+
private Collection $nestedCollection;
5252

53-
/** @var array<MultiRelationsNestedPaginated> */
53+
/** @var Collection<MultiRelationsNestedPaginated> */
5454
#[ODM\EmbedMany]
55-
private array $nestedPaginatedCollection;
55+
private Collection $nestedPaginatedCollection;
5656

5757
public function __construct()
5858
{
5959
$this->manyToManyRelations = new ArrayCollection();
6060
$this->oneToManyRelations = new ArrayCollection();
61-
$this->nestedCollection = [];
62-
$this->nestedPaginatedCollection = [];
61+
$this->nestedCollection = new ArrayCollection();
62+
$this->nestedPaginatedCollection = new ArrayCollection();
6363
}
6464

6565
public function getId(): ?int
@@ -89,24 +89,24 @@ public function addOneToManyRelation(MultiRelationsRelatedDummy $relatedMultiUse
8989

9090
public function getNestedCollection(): Collection
9191
{
92-
return new ArrayCollection($this->nestedCollection);
92+
return $this->nestedCollection;
9393
}
9494

9595
public function setNestedCollection(Collection $nestedCollection): self
9696
{
97-
$this->nestedCollection = $nestedCollection->toArray();
97+
$this->nestedCollection = $nestedCollection;
9898

9999
return $this;
100100
}
101101

102102
public function getNestedPaginatedCollection(): Collection
103103
{
104-
return new ArrayCollection($this->nestedPaginatedCollection);
104+
return $this->nestedPaginatedCollection;
105105
}
106106

107107
public function setNestedPaginatedCollection(Collection $nestedPaginatedCollection): self
108108
{
109-
$this->nestedPaginatedCollection = $nestedPaginatedCollection->toArray();
109+
$this->nestedPaginatedCollection = $nestedPaginatedCollection;
110110

111111
return $this;
112112
}

tests/Fixtures/TestBundle/Document/MultiRelationsNested.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515

1616
use ApiPlatform\Metadata\ApiResource;
1717
use ApiPlatform\Metadata\GraphQl\QueryCollection;
18+
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
1819

1920
#[ApiResource(graphQlOperations: [new QueryCollection(paginationEnabled: false, nested: true)])]
21+
#[ODM\EmbeddedDocument]
2022
class MultiRelationsNested
2123
{
24+
#[ODM\Field(type: 'string')]
2225
public ?string $name;
2326
}

tests/Fixtures/TestBundle/Document/MultiRelationsNestedPaginated.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515

1616
use ApiPlatform\Metadata\ApiResource;
1717
use ApiPlatform\Metadata\GraphQl\QueryCollection;
18+
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
1819

1920
#[ApiResource(graphQlOperations: [new QueryCollection(nested: true)])]
21+
#[ODM\EmbeddedDocument]
2022
class MultiRelationsNestedPaginated
2123
{
24+
#[ODM\Field(type: 'string')]
2225
public ?string $name;
2326
}

0 commit comments

Comments
 (0)