Skip to content

Commit 4e6dbfc

Browse files
authored
Merge pull request #1746 from alanpoulain/fix/graphql-simple-array-query
[GraphQL] Fix simple array query
2 parents d1a66d6 + acb7731 commit 4e6dbfc

16 files changed

+104
-8
lines changed

features/bootstrap/FeatureContext.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public function thereAreDummyObjectsWithRelatedDummy(int $nb)
264264
}
265265

266266
/**
267-
* @Given there are :nb dummy objects with JSON data
267+
* @Given there are :nb dummy objects with JSON and array data
268268
*/
269269
public function thereAreDummyObjectsWithJsonData(int $nb)
270270
{
@@ -273,6 +273,7 @@ public function thereAreDummyObjectsWithJsonData(int $nb)
273273
$dummy->setName('Dummy #'.$i);
274274
$dummy->setAlias('Alias #'.($nb - $i));
275275
$dummy->setJsonData(['foo' => ['bar', 'baz'], 'bar' => 5]);
276+
$dummy->setArrayData(['foo', 'bar', 'baz']);
276277

277278
$this->manager->persist($dummy);
278279
}

features/graphql/mutation.feature

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ Feature: GraphQL mutation support
8383
When I send the following GraphQL request:
8484
"""
8585
mutation {
86-
createDummy(input: {_id: 2, name: "A dummy", foo: [], jsonData: {bar:{baz:3,qux:[7.6,false,null]}}, clientMutationId: "myId"}) {
86+
createDummy(input: {_id: 2, name: "A dummy", foo: [], jsonData: {bar:{baz:3,qux:[7.6,false,null]}}, arrayData: ["bar", "baz"], clientMutationId: "myId"}) {
8787
id
8888
name
8989
foo
9090
jsonData
91+
arrayData
9192
clientMutationId
9293
}
9394
}
@@ -102,6 +103,7 @@ Feature: GraphQL mutation support
102103
And the JSON node "data.createDummy.jsonData.bar.qux[0]" should be equal to the number 7.6
103104
And the JSON node "data.createDummy.jsonData.bar.qux[1]" should be false
104105
And the JSON node "data.createDummy.jsonData.bar.qux[2]" should be null
106+
And the JSON node "data.createDummy.arrayData[1]" should be equal to baz
105107
And the JSON node "data.createDummy.clientMutationId" should be equal to "myId"
106108

107109
@dropSchema

features/graphql/query.feature

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ Feature: GraphQL query support
3636
And the JSON node "data.node.name" should be equal to "Dummy #1"
3737

3838
Scenario: Retrieve an item with an iterable field
39-
Given there are 2 dummy objects with JSON data
39+
Given there are 2 dummy objects with JSON and array data
4040
When I send the following GraphQL request:
4141
"""
4242
{
4343
dummy(id: "/dummies/3") {
4444
id
4545
name
4646
jsonData
47+
arrayData
4748
}
4849
}
4950
"""
@@ -54,6 +55,7 @@ Feature: GraphQL query support
5455
And the JSON node "data.dummy.name" should be equal to "Dummy #1"
5556
And the JSON node "data.dummy.jsonData.foo" should have 2 elements
5657
And the JSON node "data.dummy.jsonData.bar" should be equal to 5
58+
And the JSON node "data.dummy.arrayData[2]" should be equal to baz
5759

5860
Scenario: Retrieve an item through a GraphQL query with variables
5961
When I have the following GraphQL request:

features/hal/hal.feature

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Feature: HAL support
7373
"dummyFloat": null,
7474
"dummyPrice": null,
7575
"jsonData": [],
76+
"arrayData": [],
7677
"name_converted": null,
7778
"id": 1,
7879
"name": "Dummy with relations",
@@ -114,6 +115,7 @@ Feature: HAL support
114115
"dummyFloat": null,
115116
"dummyPrice": null,
116117
"jsonData": [],
118+
"arrayData": [],
117119
"name_converted": null,
118120
"id": 1,
119121
"name": "A nice dummy",
@@ -219,6 +221,7 @@ Feature: HAL support
219221
"dummyFloat": null,
220222
"dummyPrice": null,
221223
"jsonData": [],
224+
"arrayData": [],
222225
"name_converted": null,
223226
"id": 1,
224227
"name": "A nice dummy",

features/jsonld/context.feature

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Feature: JSON-LD contexts generation
3939
"@type": "@id"
4040
},
4141
"jsonData": "Dummy/jsonData",
42+
"arrayData": "Dummy/arrayData",
4243
"nameConverted": "Dummy/nameConverted",
4344
"id": "Dummy/id",
4445
"name": "http://schema.org/name",

features/main/content_negotiation.feature

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Feature: Content Negotiation support
1818
And the response should be equal to
1919
"""
2020
<?xml version="1.0"?>
21-
<response><description/><dummy/><dummyBoolean/><dummyDate/><dummyFloat/><dummyPrice/><relatedDummy/><relatedDummies/><jsonData/><name_converted/><id>1</id><name>XML!</name><alias/><foo/></response>
21+
<response><description/><dummy/><dummyBoolean/><dummyDate/><dummyFloat/><dummyPrice/><relatedDummy/><relatedDummies/><jsonData/><arrayData/><name_converted/><id>1</id><name>XML!</name><alias/><foo/></response>
2222
"""
2323

2424
Scenario: Retrieve a collection in XML
@@ -29,7 +29,7 @@ Feature: Content Negotiation support
2929
And the response should be equal to
3030
"""
3131
<?xml version="1.0"?>
32-
<response><item key="0"><description/><dummy/><dummyBoolean/><dummyDate/><dummyFloat/><dummyPrice/><relatedDummy/><relatedDummies/><jsonData/><name_converted/><id>1</id><name>XML!</name><alias/><foo/></item></response>
32+
<response><item key="0"><description/><dummy/><dummyBoolean/><dummyDate/><dummyFloat/><dummyPrice/><relatedDummy/><relatedDummies/><jsonData/><arrayData/><name_converted/><id>1</id><name>XML!</name><alias/><foo/></item></response>
3333
"""
3434

3535
Scenario: Retrieve a collection in XML using the .xml URL
@@ -39,7 +39,7 @@ Feature: Content Negotiation support
3939
And the response should be equal to
4040
"""
4141
<?xml version="1.0"?>
42-
<response><item key="0"><description/><dummy/><dummyBoolean/><dummyDate/><dummyFloat/><dummyPrice/><relatedDummy/><relatedDummies/><jsonData/><name_converted/><id>1</id><name>XML!</name><alias/><foo/></item></response>
42+
<response><item key="0"><description/><dummy/><dummyBoolean/><dummyDate/><dummyFloat/><dummyPrice/><relatedDummy/><relatedDummies/><jsonData/><arrayData/><name_converted/><id>1</id><name>XML!</name><alias/><foo/></item></response>
4343
"""
4444

4545
Scenario: Retrieve a collection in JSON
@@ -61,6 +61,7 @@ Feature: Content Negotiation support
6161
"relatedDummy": null,
6262
"relatedDummies": [],
6363
"jsonData": [],
64+
"arrayData": [],
6465
"name_converted": null,
6566
"id": 1,
6667
"name": "XML!",
@@ -82,7 +83,7 @@ Feature: Content Negotiation support
8283
And the response should be equal to
8384
"""
8485
<?xml version="1.0"?>
85-
<response><description/><dummy/><dummyBoolean/><dummyDate/><dummyFloat/><dummyPrice/><relatedDummy/><relatedDummies/><jsonData/><name_converted/><id>2</id><name>Sent in JSON</name><alias/><foo/></response>
86+
<response><description/><dummy/><dummyBoolean/><dummyDate/><dummyFloat/><dummyPrice/><relatedDummy/><relatedDummies/><jsonData/><arrayData/><name_converted/><id>2</id><name>Sent in JSON</name><alias/><foo/></response>
8687
"""
8788

8889
Scenario: Requesting the same format in the Accept header and in the URL should work

features/main/crud.feature

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Feature: Create-Retrieve-Update-Delete
4242
"value2"
4343
]
4444
},
45+
"arrayData": [],
4546
"name_converted": null,
4647
"id": 1,
4748
"name": "My Dummy",
@@ -75,6 +76,7 @@ Feature: Create-Retrieve-Update-Delete
7576
"value2"
7677
]
7778
},
79+
"arrayData": [],
7880
"name_converted": null,
7981
"id": 1,
8082
"name": "My Dummy",
@@ -116,6 +118,7 @@ Feature: Create-Retrieve-Update-Delete
116118
"value2"
117119
]
118120
},
121+
"arrayData": [],
119122
"name_converted": null,
120123
"id": 1,
121124
"name": "My Dummy",
@@ -433,6 +436,7 @@ Feature: Create-Retrieve-Update-Delete
433436
"key": "value2"
434437
}
435438
],
439+
"arrayData": [],
436440
"name_converted": null,
437441
"id": 1,
438442
"name": "A nice dummy",
@@ -469,6 +473,7 @@ Feature: Create-Retrieve-Update-Delete
469473
"key": "value2"
470474
}
471475
],
476+
"arrayData": [],
472477
"name_converted": null,
473478
"id": 1,
474479
"name": "A nice dummy",

features/main/relation.feature

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ Feature: Relations support
158158
"/related_dummies/1"
159159
],
160160
"jsonData": [],
161+
"arrayData": [],
161162
"name_converted": null,
162163
"id": 1,
163164
"name": "Dummy with relations",

features/security/strong_typing.feature

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Feature: Handle properly invalid data submitted to the API
3131
"relatedDummy": null,
3232
"relatedDummies": [],
3333
"jsonData": [],
34+
"arrayData": [],
3435
"name_converted": null,
3536
"id": 1,
3637
"name": "Not existing",

features/security/unknown_attributes.feature

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Feature: Ignore unknown attributes
3232
"relatedDummy": null,
3333
"relatedDummies": [],
3434
"jsonData": [],
35+
"arrayData": [],
3536
"name_converted": null,
3637
"id": 1,
3738
"name": "Not existing",

src/GraphQl/Type/SchemaBuilder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,6 @@ private function getResourcePaginatedCollectionType(string $resourceClass, Graph
494494

495495
private function isCollection(Type $type): bool
496496
{
497-
return $type->isCollection() && null !== $type->getCollectionValueType();
497+
return $type->isCollection() && Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType();
498498
}
499499
}

tests/Bridge/Doctrine/Orm/Filter/ExistsFilterTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public function testGetDescriptionDefaultFields()
7676
'type' => 'bool',
7777
'required' => false,
7878
],
79+
'arrayData[exists]' => [
80+
'property' => 'arrayData',
81+
'type' => 'bool',
82+
'required' => false,
83+
],
7984
'nameConverted[exists]' => [
8085
'property' => 'nameConverted',
8186
'type' => 'bool',

tests/Bridge/Doctrine/Orm/Filter/OrderFilterTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ public function testGetDescriptionDefaultFields()
9393
'type' => 'string',
9494
'required' => false,
9595
],
96+
'order[arrayData]' => [
97+
'property' => 'arrayData',
98+
'type' => 'string',
99+
'required' => false,
100+
],
96101
'order[nameConverted]' => [
97102
'property' => 'nameConverted',
98103
'type' => 'string',

tests/Bridge/Doctrine/Orm/Filter/RangeFilterTest.php

+25
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,31 @@ public function testGetDescription()
253253
'type' => 'string',
254254
'required' => false,
255255
],
256+
'arrayData[between]' => [
257+
'property' => 'arrayData',
258+
'type' => 'string',
259+
'required' => false,
260+
],
261+
'arrayData[gt]' => [
262+
'property' => 'arrayData',
263+
'type' => 'string',
264+
'required' => false,
265+
],
266+
'arrayData[gte]' => [
267+
'property' => 'arrayData',
268+
'type' => 'string',
269+
'required' => false,
270+
],
271+
'arrayData[lt]' => [
272+
'property' => 'arrayData',
273+
'type' => 'string',
274+
'required' => false,
275+
],
276+
'arrayData[lte]' => [
277+
'property' => 'arrayData',
278+
'type' => 'string',
279+
'required' => false,
280+
],
256281
'nameConverted[between]' => [
257282
'property' => 'nameConverted',
258283
'type' => 'string',

tests/Bridge/Doctrine/Orm/Filter/SearchFilterTest.php

+25
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ public function testGetDescription()
167167
'required' => false,
168168
'strategy' => 'exact',
169169
],
170+
'arrayData' => [
171+
'property' => 'arrayData',
172+
'type' => 'string',
173+
'required' => false,
174+
'strategy' => 'exact',
175+
],
176+
'arrayData[]' => [
177+
'property' => 'arrayData',
178+
'type' => 'string',
179+
'required' => false,
180+
'strategy' => 'exact',
181+
],
170182
'nameConverted' => [
171183
'property' => 'nameConverted',
172184
'type' => 'string',
@@ -200,6 +212,7 @@ public function testGetDescription()
200212
'dummy' => null,
201213
'dummyDate' => null,
202214
'jsonData' => null,
215+
'arrayData' => null,
203216
'nameConverted' => null,
204217
'foo' => null,
205218
'relatedDummies.dummyDate' => null,
@@ -279,6 +292,18 @@ public function testGetDescription()
279292
'required' => false,
280293
'strategy' => 'exact',
281294
],
295+
'arrayData' => [
296+
'property' => 'arrayData',
297+
'type' => 'string',
298+
'required' => false,
299+
'strategy' => 'exact',
300+
],
301+
'arrayData[]' => [
302+
'property' => 'arrayData',
303+
'type' => 'string',
304+
'required' => false,
305+
'strategy' => 'exact',
306+
],
282307
'nameConverted' => [
283308
'property' => 'nameConverted',
284309
'type' => 'string',

tests/Fixtures/TestBundle/Entity/Dummy.php

+18
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ class Dummy
138138
*/
139139
public $jsonData;
140140

141+
/**
142+
* @var array
143+
*
144+
* @ORM\Column(type="simple_array", nullable=true)
145+
*/
146+
public $arrayData;
147+
141148
/**
142149
* @var string
143150
*
@@ -153,6 +160,7 @@ public function __construct()
153160
{
154161
$this->relatedDummies = new ArrayCollection();
155162
$this->jsonData = [];
163+
$this->arrayData = [];
156164
}
157165

158166
public function getId()
@@ -241,6 +249,16 @@ public function getJsonData()
241249
return $this->jsonData;
242250
}
243251

252+
public function setArrayData($arrayData)
253+
{
254+
$this->arrayData = $arrayData;
255+
}
256+
257+
public function getArrayData()
258+
{
259+
return $this->arrayData;
260+
}
261+
244262
public function getRelatedDummy()
245263
{
246264
return $this->relatedDummy;

0 commit comments

Comments
 (0)