@@ -66,28 +66,30 @@ public function createItemMutationResolver(string $resourceClass, string $mutati
66
66
$ id = $ args ['input ' ][$ identifiers [0 ]];
67
67
}
68
68
69
- if ('delete ' === $ mutationName ) {
69
+ if ('update ' === $ mutationName || ' delete ' === $ mutationName ) {
70
70
$ item = $ this ->itemDataProvider ->getItem ($ resourceClass , $ id );
71
-
72
71
if (null === $ item ) {
73
72
throw Error::createLocatedError ("Item $ resourceClass $ id not found " , $ info ->fieldNodes , $ info ->path );
74
73
}
74
+ }
75
75
76
- $ this ->dataPersister ->remove ($ item );
76
+ switch ($ mutationName ) {
77
+ case 'delete ' :
78
+ $ this ->dataPersister ->remove ($ item );
77
79
78
- return $ args ['input ' ];
79
- } elseif ('update ' === $ mutationName ) {
80
- $ item = $ this ->serializer ->denormalize ($ args ['input ' ], $ resourceClass , null , ['resource_class ' => $ resourceClass ]);
80
+ return $ args ['input ' ];
81
81
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 );
83
85
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
+ );
91
93
}
92
94
};
93
95
}
0 commit comments