1
|
|
|
<?php |
2
|
|
|
/******************************************************************************* |
3
|
|
|
* This file is part of the GraphQL Bundle package. |
4
|
|
|
* |
5
|
|
|
* (c) YnloUltratech <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
******************************************************************************/ |
10
|
|
|
|
11
|
|
|
namespace Ynlo\GraphQLBundle\Definition\Loader\Annotation; |
12
|
|
|
|
13
|
|
|
use Ynlo\GraphQLBundle\Annotation; |
14
|
|
|
use Ynlo\GraphQLBundle\Definition\Registry\Endpoint; |
15
|
|
|
use Ynlo\GraphQLBundle\Form\Node\NodeDeleteInput; |
16
|
|
|
use Ynlo\GraphQLBundle\Model\DeleteNodePayload; |
17
|
|
|
use Ynlo\GraphQLBundle\Model\NodeInterface; |
18
|
|
|
use Ynlo\GraphQLBundle\Mutation\DeleteNode; |
19
|
|
|
use Ynlo\GraphQLBundle\Util\ClassUtils; |
20
|
|
|
|
21
|
|
|
class MutationDeleteAnnotationParser extends MutationAnnotationParser |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
22 |
|
public function supports($annotation): bool |
27
|
|
|
{ |
28
|
22 |
|
return $annotation instanceof Annotation\MutationDelete; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
* |
34
|
|
|
* @param Annotation\MutationDelete $annotation |
35
|
|
|
*/ |
36
|
22 |
|
public function parse($annotation, \ReflectionClass $refClass, Endpoint $endpoint) |
37
|
|
|
{ |
38
|
22 |
|
if (!$endpoint->hasTypeForClass($refClass->getName())) { |
39
|
|
|
throw new \RuntimeException(sprintf('Can\'t apply Delete operation to "%s", CRUD operations can only be applied to valid GraphQL object types.', $refClass->getName())); |
40
|
|
|
} |
41
|
|
|
|
42
|
22 |
|
if (!$refClass->implementsInterface(NodeInterface::class)) { |
43
|
|
|
throw new \RuntimeException(sprintf('Can\'t apply Delete operation to "%s", CRUD operations can only be applied to nodes. You are implementing NodeInterface in this class?', $refClass->getName())); |
44
|
|
|
} |
45
|
|
|
|
46
|
22 |
|
$definition = $endpoint->getType($endpoint->getTypeForClass($refClass->getName())); |
47
|
22 |
|
$bundleNamespace = ClassUtils::relatedBundleNamespace($refClass->getName()); |
48
|
|
|
|
49
|
22 |
|
$annotation->name = $annotation->name ?? 'delete'.ucfirst($definition->getName()); |
50
|
22 |
|
$annotation->payload = $annotation->payload ?? null; |
51
|
22 |
|
if (!$annotation->payload) { |
52
|
22 |
|
$annotation->payload = DeleteNodePayload::class; |
53
|
|
|
} |
54
|
22 |
|
$annotation->node = $annotation->node ?? $definition->getName(); |
55
|
22 |
|
$annotation->options = array_merge(['form' => ['type' => NodeDeleteInput::class]], $annotation->options); |
56
|
22 |
|
$resolverReflection = new \ReflectionClass(DeleteNode::class); |
57
|
|
|
|
58
|
22 |
|
$resolver = ClassUtils::applyNamingConvention($bundleNamespace, 'Mutation', $definition->getName(), $annotation->name); |
59
|
22 |
|
if (class_exists($resolver)) { |
60
|
|
|
$annotation->resolver = $resolver; |
61
|
|
|
} |
62
|
|
|
|
63
|
22 |
|
parent::parse($annotation, $resolverReflection, $endpoint); |
64
|
22 |
|
} |
65
|
|
|
} |
66
|
|
|
|