Skip to content

Commit 05a84f0

Browse files
alanpoulaindunglas
authored andcommitted
[GraphQL] Fix update mutation when ID can be denormalized (#1783)
* Add a failing test for an update mutation * Remove useless create/dropSchema in mutation.feature * Unset the ID in mutation resolver
1 parent 7269be4 commit 05a84f0

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

features/graphql/mutation.feature

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ Feature: GraphQL mutation support
106106
And the JSON node "data.createDummy.arrayData[1]" should be equal to baz
107107
And the JSON node "data.createDummy.clientMutationId" should be equal to "myId"
108108

109-
@dropSchema
110109
Scenario: Delete an item through a mutation
111110
When I send the following GraphQL request:
112111
"""
@@ -123,7 +122,6 @@ Feature: GraphQL mutation support
123122
And the JSON node "data.deleteFoo.id" should be equal to "/foos/1"
124123
And the JSON node "data.deleteFoo.clientMutationId" should be equal to "anotherId"
125124

126-
@createSchema
127125
@dropSchema
128126
Scenario: Delete an item with composite identifiers through a mutation
129127
Given there are Composite identifier objects
@@ -143,29 +141,29 @@ Feature: GraphQL mutation support
143141
And the JSON node "data.deleteCompositeRelation.clientMutationId" should be equal to "myId"
144142

145143
@createSchema
146-
@dropSchema
147144
Scenario: Modify an item through a mutation
148-
Given there are 1 foo objects with fake names
145+
Given there are 1 dummy objects
149146
When I send the following GraphQL request:
150147
"""
151148
mutation {
152-
updateFoo(input: {id: "/foos/1", bar: "Modified description.", clientMutationId: "myId"}) {
149+
updateDummy(input: {id: "/dummies/1", description: "Modified description.", dummyDate: "2018-06-05", clientMutationId: "myId"}) {
153150
id
154151
name
155-
bar
152+
description
153+
dummyDate
156154
clientMutationId
157155
}
158156
}
159157
"""
160158
Then the response status code should be 200
161159
And the response should be in JSON
162160
And the header "Content-Type" should be equal to "application/json"
163-
And the JSON node "data.updateFoo.id" should be equal to "/foos/1"
164-
And the JSON node "data.updateFoo.name" should be equal to "Hawsepipe"
165-
And the JSON node "data.updateFoo.bar" should be equal to "Modified description."
166-
And the JSON node "data.updateFoo.clientMutationId" should be equal to "myId"
161+
And the JSON node "data.updateDummy.id" should be equal to "/dummies/1"
162+
And the JSON node "data.updateDummy.name" should be equal to "Dummy #1"
163+
And the JSON node "data.updateDummy.description" should be equal to "Modified description."
164+
And the JSON node "data.updateDummy.dummyDate" should be equal to "2018-06-05T00:00:00+00:00"
165+
And the JSON node "data.updateDummy.clientMutationId" should be equal to "myId"
167166

168-
@createSchema
169167
Scenario: Modify an item with composite identifiers through a mutation
170168
Given there are Composite identifier objects
171169
When I send the following GraphQL request:

src/GraphQl/Resolver/Factory/ItemMutationResolverFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public function __invoke(string $resourceClass = null, string $rootClass = null,
8585
switch ($operationName) {
8686
case 'create':
8787
case 'update':
88+
unset($args['input']['id']);
8889
$context = null === $item ? ['resource_class' => $resourceClass] : ['resource_class' => $resourceClass, 'object_to_populate' => $item];
8990
$item = $this->normalizer->denormalize($args['input'], $resourceClass, ItemNormalizer::FORMAT, $context);
9091
$this->validate($item, $info, $resourceMetadata, $operationName);

0 commit comments

Comments
 (0)