AbstractDeleteEntityField   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 3 1
A getDescription() 0 3 1
A getType() 0 3 1
A resolve() 0 7 1
1
<?php
2
3
namespace Digia\Lumen\GraphQL\Fields;
4
5
use Digia\Lumen\GraphQL\Models\ResolveContext;
6
use Digia\Lumen\GraphQL\Traits\ResolvesNodesTrait;
7
use Youshido\GraphQL\Config\Field\FieldConfig;
8
use Youshido\GraphQL\Execution\ResolveInfo;
9
use Youshido\GraphQL\Field\AbstractField;
10
use Youshido\GraphQL\Type\NonNullType;
11
use Youshido\GraphQL\Type\Scalar\BooleanType;
12
use Youshido\GraphQL\Type\Scalar\IdType;
13
14
/**
15
 * Class AbstractDeleteEntityField
16
 * @package Digia\Lumen\GraphQL\Fields
17
 */
18
abstract class AbstractDeleteEntityField extends AbstractField
19
{
20
21
    use ResolvesNodesTrait;
22
23
    /**
24
     * @param ResolveContext $context
25
     * @return mixed
26
     */
27
    abstract protected function deleteEntity(ResolveContext $context);
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function getType()
33
    {
34
        return new BooleanType();
35
    }
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public function getDescription()
41
    {
42
        return 'Deletes an existing entity.';
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function build(FieldConfig $config)
49
    {
50
        $config->addArgument('id', new NonNullType(new IdType()));
51
    }
52
53
    /**
54
     * @inheritdoc
55
     */
56
    public function resolve($value, array $args, ResolveInfo $info)
57
    {
58
        $context = new ResolveContext($value, $args, $info);
59
60
        $this->deleteEntity($context);
61
62
        return true;
63
    }
64
}
65