Skip to content

Commit 4b670a1

Browse files
committed
Use InputUnionType for updating related existing resources
1 parent 1631e83 commit 4b670a1

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

features/graphql/mutation.feature

+22
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,28 @@ Feature: GraphQL mutation support
122122
And the JSON node "data.createRelatedDummy.id" should be equal to "/related_dummies/2"
123123
And the JSON node "data.createRelatedDummy.clientMutationId" should be equal to "myId"
124124

125+
Scenario: Create an item and update a nested resource through a mutation
126+
When I send the following GraphQL request:
127+
"""
128+
mutation {
129+
createRelationEmbedder(input: {paris: "paris", krondstadt: "Krondstadt", anotherRelated: {id: 2, symfony: "laravel"}, clientMutationId: "myId"}) {
130+
id
131+
anotherRelated {
132+
id
133+
symfony
134+
}
135+
clientMutationId
136+
}
137+
}
138+
"""
139+
Then the response status code should be 200
140+
And the response should be in JSON
141+
And the header "Content-Type" should be equal to "application/json"
142+
And the JSON node "data.createRelationEmbedder.id" should be equal to "/relation_embedders/1"
143+
And the JSON node "data.createRelationEmbedder.anotherRelated.id" should be equal to "/related_dummies/2"
144+
And the JSON node "data.createRelationEmbedder.anotherRelated.symfony" should be equal to "laravel"
145+
And the JSON node "data.createRelationEmbedder.clientMutationId" should be equal to "myId"
146+
125147
Scenario: Delete an item through a mutation
126148
When I send the following GraphQL request:
127149
"""

src/GraphQl/Serializer/ItemNormalizer.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323

2424
use ApiPlatform\Core\Metadata\Property\PropertyMetadata;
2525
use ApiPlatform\Core\Serializer\AbstractItemNormalizer;
26+
use ApiPlatform\Core\Serializer\ItemNormalizer as GenericItemNormalizer;
2627

2728
/**
2829
* GraphQL normalizer.
2930
*
3031
* @author Kévin Dunglas <[email protected]>
3132
*/
32-
final class ItemNormalizer extends AbstractItemNormalizer
33+
final class ItemNormalizer extends GenericItemNormalizer
3334
{
3435
const FORMAT = 'graphql';
3536
const ITEM_KEY = '#item';
@@ -39,7 +40,7 @@ final class ItemNormalizer extends AbstractItemNormalizer
3940
*/
4041
public function normalize($object, $format = null, array $context = [])
4142
{
42-
$data = parent::normalize($object, $format, $context);
43+
$data = AbstractItemNormalizer::normalize($object, $format, $context);
4344
$data[self::ITEM_KEY] = serialize($object); // calling serialize prevent weird normalization process done by Webonyx's GraphQL PHP
4445

4546
return $data;

0 commit comments

Comments
 (0)