@@ -89,7 +89,7 @@ public function __invoke(string $resourceClass = null, string $rootClass = null,
8989 $ normalizationContext = $ baseNormalizationContext ;
9090 $ normalizationContext ['resource_class ' ] = $ resourceClass ;
9191
92- if (isset ($ args ['input ' ]['id ' ])) {
92+ if (isset ($ args ['input ' ]['id ' ]) && $ resourceMetadata -> getGraphqlAttribute ( $ operationName , ' read ' , true , true ) ) {
9393 try {
9494 $ item = $ this ->iriConverter ->getItemFromIri ($ args ['input ' ]['id ' ], $ baseNormalizationContext );
9595 } catch (ItemNotFoundException $ e ) {
@@ -123,10 +123,14 @@ public function __invoke(string $resourceClass = null, string $rootClass = null,
123123 'previous_object ' => $ previousItem ,
124124 ], $ operationName );
125125
126- $ data [$ wrapFieldName ]['id ' ] = null ;
127- if ($ item ) {
126+ if ($ item && $ resourceMetadata ->getGraphqlAttribute ($ operationName , 'write ' , true , true )) {
128127 $ this ->dataPersister ->remove ($ item );
128+ }
129+
130+ if ($ resourceMetadata ->getGraphqlAttribute ($ operationName , 'serialize ' , true , true )) {
129131 $ data [$ wrapFieldName ]['id ' ] = $ args ['input ' ]['id ' ];
132+
133+ return $ data ;
130134 }
131135
132136 return $ data ;
@@ -137,7 +141,9 @@ public function __invoke(string $resourceClass = null, string $rootClass = null,
137141 $ denormalizationContext ['object_to_populate ' ] = $ item ;
138142 }
139143 $ denormalizationContext += $ resourceMetadata ->getGraphqlAttribute ($ operationName , 'denormalization_context ' , [], true );
140- $ item = $ this ->normalizer ->denormalize ($ args ['input ' ], $ inputClass ?: $ resourceClass , ItemNormalizer::FORMAT , $ denormalizationContext );
144+ if ($ resourceMetadata ->getGraphqlAttribute ($ operationName , 'deserialize ' , true , true )) {
145+ $ item = $ this ->normalizer ->denormalize ($ args ['input ' ], $ inputClass ?: $ resourceClass , ItemNormalizer::FORMAT , $ denormalizationContext );
146+ }
141147
142148 $ mutationResolverId = $ resourceMetadata ->getGraphqlAttribute ($ operationName , 'mutation ' );
143149 if (null !== $ mutationResolverId ) {
@@ -155,15 +161,24 @@ public function __invoke(string $resourceClass = null, string $rootClass = null,
155161 ], $ operationName );
156162
157163 if (null !== $ item ) {
158- $ this ->validate ($ item , $ info , $ resourceMetadata , $ operationName );
164+ if ($ resourceMetadata ->getGraphqlAttribute ($ operationName , 'validate ' , true , true )) {
165+ $ this ->validate ($ item , $ info , $ resourceMetadata , $ operationName );
166+ }
167+
168+ if ($ resourceMetadata ->getGraphqlAttribute ($ operationName , 'write ' , true , true )) {
169+ $ persistResult = $ this ->dataPersister ->persist ($ item , $ denormalizationContext );
159170
160- $ persistResult = $ this -> dataPersister -> persist ( $ item , $ denormalizationContext );
161- if (! \is_object ( $ persistResult )) {
162- @ trigger_error ( sprintf ( ' Not returning an object from %s::persist() is deprecated since API Platform 2.3 and will not be supported in API Platform 3. ' , DataPersisterInterface::class), E_USER_DEPRECATED );
171+ if (! \is_object ( $ persistResult )) {
172+ @ trigger_error ( sprintf ( ' Not returning an object from %s::persist() is deprecated since API Platform 2.3 and will not be supported in API Platform 3. ' , DataPersisterInterface::class), E_USER_DEPRECATED );
173+ }
163174 }
164175 }
165176
166- return [$ wrapFieldName => $ this ->normalizer ->normalize ($ persistResult ?? $ item , ItemNormalizer::FORMAT , $ normalizationContext )] + $ data ;
177+ if ($ resourceMetadata ->getGraphqlAttribute ($ operationName , 'serialize ' , true , true )) {
178+ return [$ wrapFieldName => $ this ->normalizer ->normalize ($ persistResult ?? $ item , ItemNormalizer::FORMAT , $ normalizationContext )] + $ data ;
179+ }
180+
181+ return $ data ;
167182 };
168183 }
169184
0 commit comments