Skip to content

Commit e07e791

Browse files
committed
Merge branch '2.2'
2 parents dd2d49e + c475c1e commit e07e791

25 files changed

+355
-54
lines changed

features/graphql/introspection.feature

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,71 @@ Feature: GraphQL introspection support
187187
And the JSON node "data.__type.fields[9].name" should be equal to "jsonData"
188188
And the JSON node "data.__type.fields[9].type.name" should be equal to "Iterable"
189189

190+
Scenario: Retrieve entity - using serialization groups - fields
191+
When I send the following GraphQL request:
192+
"""
193+
{
194+
typeQuery: __type(name: "DummyGroup") {
195+
description,
196+
fields {
197+
name
198+
type {
199+
name
200+
kind
201+
ofType {
202+
name
203+
kind
204+
}
205+
}
206+
}
207+
}
208+
typeCreateInput: __type(name: "createDummyGroupInput") {
209+
description,
210+
inputFields {
211+
name
212+
type {
213+
name
214+
kind
215+
ofType {
216+
name
217+
kind
218+
}
219+
}
220+
}
221+
}
222+
typeCreatePayload: __type(name: "createDummyGroupPayload") {
223+
description,
224+
fields {
225+
name
226+
type {
227+
name
228+
kind
229+
ofType {
230+
name
231+
kind
232+
}
233+
}
234+
}
235+
}
236+
}
237+
"""
238+
Then the response status code should be 200
239+
And the response should be in JSON
240+
And the header "Content-Type" should be equal to "application/json"
241+
And the JSON node "data.typeQuery.fields" should have 2 elements
242+
And the JSON node "data.typeQuery.fields[0].name" should be equal to "id"
243+
And the JSON node "data.typeQuery.fields[1].name" should be equal to "foo"
244+
And the JSON node "data.typeCreateInput.inputFields" should have 3 elements
245+
And the JSON node "data.typeCreateInput.inputFields[0].name" should be equal to "bar"
246+
And the JSON node "data.typeCreateInput.inputFields[1].name" should be equal to "baz"
247+
And the JSON node "data.typeCreateInput.inputFields[2].name" should be equal to "clientMutationId"
248+
And the JSON node "data.typeCreatePayload.fields" should have 4 elements
249+
And the JSON node "data.typeCreatePayload.fields[0].name" should be equal to "id"
250+
And the JSON node "data.typeCreatePayload.fields[1].name" should be equal to "bar"
251+
And the JSON node "data.typeCreatePayload.fields[2].name" should be equal to "baz"
252+
And the JSON node "data.typeCreatePayload.fields[3].name" should be equal to "clientMutationId"
253+
254+
@dropSchema
190255
Scenario: Retrieve an item through a GraphQL query
191256
Given there are 4 dummy objects with relatedDummy
192257
When I send the following GraphQL request:

features/graphql/mutation.feature

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,27 @@ Feature: GraphQL mutation support
221221
And the JSON node "data.updateWritableId.name" should be equal to "Foo"
222222
And the JSON node "data.updateWritableId.clientMutationId" should be equal to "m"
223223

224+
Scenario: Use serialization groups
225+
Given there are 1 dummy group objects
226+
When I send the following GraphQL request:
227+
"""
228+
mutation {
229+
createDummyGroup(input: {bar: "Bar", baz: "Baz", clientMutationId: "myId"}) {
230+
id
231+
bar
232+
baz
233+
clientMutationId
234+
}
235+
}
236+
"""
237+
Then the response status code should be 200
238+
And the response should be in JSON
239+
And the header "Content-Type" should be equal to "application/json"
240+
And the JSON node "data.createDummyGroup.id" should be equal to "/dummy_groups/2"
241+
And the JSON node "data.createDummyGroup.bar" should be equal to "Bar"
242+
And the JSON node "data.createDummyGroup.baz" should be null
243+
And the JSON node "data.createDummyGroup.clientMutationId" should be equal to "myId"
244+
224245
@dropSchema
225246
Scenario: Trigger a validation error
226247
When I send the following GraphQL request:

features/graphql/query.feature

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@ Feature: GraphQL query support
109109
And I send the GraphQL request with operation "DummyWithId1"
110110
And the JSON node "data.dummyItem.name" should be equal to "Dummy #1"
111111

112+
Scenario: Use serialization groups
113+
Given there are 1 dummy group objects
114+
When I send the following GraphQL request:
115+
"""
116+
{
117+
dummyGroup(id: "/dummy_groups/1") {
118+
foo
119+
}
120+
}
121+
"""
122+
Then the response status code should be 200
123+
And the response should be in JSON
124+
And the header "Content-Type" should be equal to "application/json"
125+
And the JSON node "data.dummyGroup.foo" should be equal to "Foo #1"
126+
127+
@dropSchema
112128
Scenario: Retrieve an nonexistent item through a GraphQL query
113129
When I send the following GraphQL request:
114130
"""
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Feature: JSON API Inclusion of Related Resources
2+
In order to be able to handle inclusion of related resources
3+
As a client software developer
4+
I need to be able to specify include parameters according to JSON API recommendation
5+
6+
Background:
7+
Given I add "Accept" header equal to "application/vnd.api+json"
8+
And I add "Content-Type" header equal to "application/vnd.api+json"
9+
10+
@createSchema
11+
@dropSchema
12+
Scenario: Request inclusion of a related resources on collection
13+
Given there are 3 dummy objects
14+
When I send a "GET" request to "/dummies/1?include=foo"
15+
Then the response status code should be 400
16+
And the response should be in JSON
17+

features/main/relation.feature

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Feature: Relations support
9797
"@id": "/related_to_dummy_friends/dummyFriend=1;relatedDummy=1",
9898
"@type": "RelatedToDummyFriend",
9999
"name": "Friends relation",
100+
"description": null,
100101
"dummyFriend": {
101102
"@id": "/dummy_friends/1",
102103
"@type": "DummyFriend",
@@ -117,6 +118,7 @@ Feature: Relations support
117118
"@id": "/related_to_dummy_friends/dummyFriend=1;relatedDummy=1",
118119
"@type": "RelatedToDummyFriend",
119120
"name": "Friends relation",
121+
"description": null,
120122
"dummyFriend": {
121123
"@id": "/dummy_friends/1",
122124
"@type": "DummyFriend",
@@ -512,13 +514,50 @@ Feature: Relations support
512514
}
513515
"""
514516

517+
Scenario: Passing a (valid) plain identifier on a relation
518+
When I add "Content-Type" header equal to "application/json"
519+
And I send a "POST" request to "/dummies" with body:
520+
"""
521+
{
522+
"relatedDummy": "1",
523+
"relatedDummies": ["1"],
524+
"name": "Dummy with plain relations"
525+
}
526+
"""
527+
Then the response status code should be 201
528+
And the response should be in JSON
529+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
530+
And the JSON should be equal to:
531+
"""
532+
{
533+
"@context":"/contexts/Dummy",
534+
"@id":"/dummies/2",
535+
"@type":"Dummy",
536+
"description":null,
537+
"dummy":null,
538+
"dummyBoolean":null,
539+
"dummyDate":null,
540+
"dummyFloat":null,
541+
"dummyPrice":null,
542+
"relatedDummy":"/related_dummies/1",
543+
"relatedDummies":["/related_dummies/1"],
544+
"jsonData":[],
545+
"arrayData":[],
546+
"name_converted":null,
547+
"id":2,
548+
"name":"Dummy with plain relations",
549+
"alias":null,
550+
"foo":null
551+
}
552+
"""
553+
515554
@dropSchema
516555
Scenario: Passing an invalid IRI to a relation
517556
When I add "Content-Type" header equal to "application/ld+json"
518557
And I send a "POST" request to "/relation_embedders" with body:
519558
"""
520559
{
521-
"related": "certainly not an iri"
560+
"related": "certainly not an iri and not a plain identifier"
522561
}
523562
"""
524563
Then the response status code should be 400

features/swagger/docs.feature

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ Feature: Documentation support
6969
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters[1].in" should be equal to "query"
7070
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters[1].required" should be false
7171
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters[1].type" should be equal to "string"
72-
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters" should have 2 element
72+
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters[2].name" should be equal to "description"
73+
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters[2].in" should be equal to "query"
74+
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters[2].required" should be false
75+
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters[2].type" should be equal to "string"
76+
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters" should have 3 element
7377

7478
# Subcollection - check schema
7579
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.responses.200.schema.items.$ref" should be equal to "#/definitions/RelatedToDummyFriend-fakemanytomany"

src/Bridge/Symfony/Bundle/Resources/config/hydra.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<service id="api_platform.hydra.normalizer.constraint_violation_list" class="ApiPlatform\Core\Hydra\Serializer\ConstraintViolationListNormalizer" public="false">
3333
<argument type="service" id="api_platform.router" />
3434
<argument>%api_platform.validator.serialize_payload_fields%</argument>
35+
<argument type="service" id="api_platform.name_converter" on-invalid="ignore" />
3536

3637
<tag name="serializer.normalizer" priority="64" />
3738
</service>

src/Bridge/Symfony/Bundle/Resources/config/jsonapi.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
</service>
5858

5959
<!-- Event listener -->
60+
<service id="api_platform.jsonapi.listener.request.include_parameters" class="ApiPlatform\Core\JsonApi\EventListener\IncludeParametersListener">
61+
<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="5" />
62+
</service>
6063

6164
<service id="api_platform.jsonapi.listener.request.transform_pagination_parameters" class="ApiPlatform\Core\JsonApi\EventListener\TransformPaginationParametersListener">
6265
<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="5" />

src/Bridge/Symfony/Bundle/Resources/config/problem.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<service id="api_platform.problem.normalizer.constraint_violation_list" class="ApiPlatform\Core\Problem\Serializer\ConstraintViolationListNormalizer" public="false">
1616
<argument>%api_platform.validator.serialize_payload_fields%</argument>
17+
<argument type="service" id="api_platform.name_converter" on-invalid="ignore" />
1718

1819
<tag name="serializer.normalizer" priority="16" />
1920
</service>

src/Cache/CachedTrait.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,18 @@ private function getCached(string $cacheKey, callable $getValue)
3333

3434
try {
3535
$cacheItem = $this->cacheItemPool->getItem($cacheKey);
36-
37-
if ($cacheItem->isHit()) {
38-
return $this->localCache[$cacheKey] = $cacheItem->get();
39-
}
4036
} catch (CacheException $e) {
41-
//do nothing
37+
return $this->localCache[$cacheKey] = $getValue();
4238
}
4339

44-
$value = $getValue();
45-
46-
if (!isset($cacheItem)) {
47-
return $this->localCache[$cacheKey] = $value;
40+
if ($cacheItem->isHit()) {
41+
return $this->localCache[$cacheKey] = $cacheItem->get();
4842
}
4943

50-
try {
51-
$cacheItem->set($value);
52-
$this->cacheItemPool->save($cacheItem);
53-
} catch (CacheException $e) {
54-
// do nothing
55-
}
44+
$value = $getValue();
45+
46+
$cacheItem->set($value);
47+
$this->cacheItemPool->save($cacheItem);
5648

5749
return $this->localCache[$cacheKey] = $value;
5850
}

0 commit comments

Comments
 (0)