Skip to content

Commit 92f4b07

Browse files
committed
Use object_to_populate
1 parent a840669 commit 92f4b07

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/Bridge/Graphql/Resolver/ItemMutationResolverFactory.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,30 @@ public function createItemMutationResolver(string $resourceClass, string $mutati
6666
$id = $args['input'][$identifiers[0]];
6767
}
6868

69-
if ('delete' === $mutationName) {
69+
if ('update' === $mutationName || 'delete' === $mutationName) {
7070
$item = $this->itemDataProvider->getItem($resourceClass, $id);
71-
7271
if (null === $item) {
7372
throw Error::createLocatedError("Item $resourceClass $id not found", $info->fieldNodes, $info->path);
7473
}
74+
}
7575

76-
$this->dataPersister->remove($item);
76+
switch ($mutationName) {
77+
case 'delete':
78+
$this->dataPersister->remove($item);
7779

78-
return $args['input'];
79-
} elseif ('update' === $mutationName) {
80-
$item = $this->serializer->denormalize($args['input'], $resourceClass, null, ['resource_class' => $resourceClass]);
80+
return $args['input'];
8181

82-
$this->dataPersister->persist($item);
82+
case 'update':
83+
$item = $this->serializer->denormalize($args['input'], $resourceClass, null, ['resource_class' => $resourceClass, 'object_to_populate' => $item]);
84+
$this->dataPersister->persist($item);
8385

84-
return $this->serializer->normalize(
85-
$item,
86-
null,
87-
['graphql' => true] + $this->resourceMetadataFactory
88-
->create($resourceClass)
89-
->getGraphqlAttribute($mutationName, 'normalization_context', [], true)
90-
);
86+
return $this->serializer->normalize(
87+
$item,
88+
null,
89+
['graphql' => true] + $this->resourceMetadataFactory
90+
->create($resourceClass)
91+
->getGraphqlAttribute($mutationName, 'normalization_context', [], true)
92+
);
9193
}
9294
};
9395
}

0 commit comments

Comments
 (0)