@@ 205-248 (lines=44) @@ | ||
202 | * @param Endpoint $endpoint |
|
203 | * @param string $bundleNamespace |
|
204 | */ |
|
205 | protected function createAddOperation(ObjectDefinitionInterface $definition, Annotation\Mutation $mutation, Endpoint $endpoint, $bundleNamespace) |
|
206 | { |
|
207 | $mutation->name = $mutation->name ?? 'add'.ucfirst($definition->getName()); |
|
208 | $mutation->payload = $mutation->payload ?? null; |
|
209 | if (!$mutation->payload) { |
|
210 | //deep cloning |
|
211 | /** @var ObjectDefinitionInterface $payload */ |
|
212 | $payload = unserialize(serialize($endpoint->getType(AddNodePayload::class)), [DefinitionInterface::class]); |
|
213 | $payload->setName(ucfirst($mutation->name.'Payload')); |
|
214 | ||
215 | if (!$endpoint->hasType($payload->getName())) { |
|
216 | $payload->getField('node')->setType($definition->getName()); |
|
217 | $endpoint->add($payload); |
|
218 | } |
|
219 | ||
220 | $mutation->payload = $payload->getName(); |
|
221 | } |
|
222 | $mutation->node = $mutation->node ?? $definition->getName(); |
|
223 | ||
224 | if ($endpoint->hasTypeForClass($mutation->node)) { |
|
225 | $mutation->node = $endpoint->getTypeForClass($mutation->node); |
|
226 | } |
|
227 | ||
228 | $formType = true; |
|
229 | $options = []; |
|
230 | $generalForm = ClassUtils::applyNamingConvention($bundleNamespace, 'Form\Input', $mutation->node, $mutation->node, 'Input'); |
|
231 | $specificForm = ClassUtils::applyNamingConvention($bundleNamespace, 'Form\Input', $mutation->node, $mutation->name, 'Input'); |
|
232 | if (class_exists($specificForm)) { |
|
233 | $formType = $specificForm; |
|
234 | } elseif (class_exists($generalForm)) { |
|
235 | $formType = $generalForm; |
|
236 | $options['operation'] = $mutation->name; |
|
237 | } |
|
238 | ||
239 | $mutation->options = array_merge(['form' => ['type' => $formType, 'options' => $options]], $mutation->options); |
|
240 | $resolverReflection = new \ReflectionClass(AddNode::class); |
|
241 | ||
242 | $resolver = ClassUtils::applyNamingConvention($bundleNamespace, 'Mutation', $definition->getName(), $mutation->name); |
|
243 | if (class_exists($resolver)) { |
|
244 | $mutation->resolver = $resolver; |
|
245 | } |
|
246 | ||
247 | $this->mutationParser->parse($mutation, $resolverReflection, $endpoint); |
|
248 | } |
|
249 | ||
250 | /** |
|
251 | * @param ObjectDefinitionInterface $definition |
|
@@ 256-299 (lines=44) @@ | ||
253 | * @param Endpoint $endpoint |
|
254 | * @param string $bundleNamespace |
|
255 | */ |
|
256 | protected function createUpdateOperation(ObjectDefinitionInterface $definition, Annotation\Mutation $mutation, Endpoint $endpoint, $bundleNamespace) |
|
257 | { |
|
258 | $mutation->name = $mutation->name ?? 'update'.ucfirst($definition->getName()); |
|
259 | $mutation->payload = $mutation->payload ?? null; |
|
260 | if (!$mutation->payload) { |
|
261 | //deep cloning |
|
262 | /** @var ObjectDefinitionInterface $payload */ |
|
263 | $payload = unserialize(serialize($endpoint->getType(UpdateNodePayload::class)), [DefinitionInterface::class]); |
|
264 | $payload->setName(ucfirst($mutation->name.'Payload')); |
|
265 | ||
266 | if (!$endpoint->hasType($payload->getName())) { |
|
267 | $payload->getField('node')->setType($definition->getName()); |
|
268 | $endpoint->add($payload); |
|
269 | } |
|
270 | ||
271 | $mutation->payload = $payload->getName(); |
|
272 | } |
|
273 | $mutation->node = $mutation->node ?? $definition->getName(); |
|
274 | ||
275 | if ($endpoint->hasTypeForClass($mutation->node)) { |
|
276 | $mutation->node = $endpoint->getTypeForClass($mutation->node); |
|
277 | } |
|
278 | ||
279 | $formType = true; |
|
280 | $options = []; |
|
281 | $generalForm = ClassUtils::applyNamingConvention($bundleNamespace, 'Form\Input', $mutation->node, $mutation->node, 'Input'); |
|
282 | $specificForm = ClassUtils::applyNamingConvention($bundleNamespace, 'Form\Input', $mutation->node, $mutation->name, 'Input'); |
|
283 | if (class_exists($specificForm)) { |
|
284 | $formType = $specificForm; |
|
285 | } elseif (class_exists($generalForm)) { |
|
286 | $formType = $generalForm; |
|
287 | $options['operation'] = $mutation->name; |
|
288 | } |
|
289 | ||
290 | $mutation->options = array_merge(['form' => ['type' => $formType, 'options' => $options]], $mutation->options); |
|
291 | $resolverReflection = new \ReflectionClass(UpdateNode::class); |
|
292 | ||
293 | $resolver = ClassUtils::applyNamingConvention($bundleNamespace, 'Mutation', $definition->getName(), $mutation->name); |
|
294 | if (class_exists($resolver)) { |
|
295 | $mutation->resolver = $resolver; |
|
296 | } |
|
297 | ||
298 | $this->mutationParser->parse($mutation, $resolverReflection, $endpoint); |
|
299 | } |
|
300 | ||
301 | /** |
|
302 | * @param ObjectDefinitionInterface $definition |