Passed
Pull Request — master (#298)
by Christoffer
02:22
created

AbstractResolver::beforeResolve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 5
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Digia\GraphQL\Schema\Resolver;
4
5
use Digia\GraphQL\Execution\ResolveInfo;
6
7
abstract class AbstractResolver implements ClassResolverInterface
8
{
9
    /**
10
     * @param mixed       $rootValue
11
     * @param mixed       $contextValues
12
     * @param ResolveInfo $info
13
     * @return callable|null
14
     */
15
    abstract public function resolveType($rootValue, $contextValues, ResolveInfo $info): ?callable;
16
17
    /**
18
     * @inheritdoc
19
     */
20
    public function beforeResolve(
21
        callable $resolveCallback,
22
        $rootValue,
23
        array $args,
24
        $contextValues = null,
25
        ?ResolveInfo $info = null
26
    ) {
27
        // Override this method to perform logic before the resolver is invoked.
28
        return $resolveCallback($rootValue, $args, $contextValues, $info);
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function afterResolve(
35
        $result,
36
        $rootValue,
37
        array $args,
38
        $contextValues = null,
39
        ?ResolveInfo $info = null
40
    ) {
41
        // Override this method to perform logic after the resolver is invoked.
42
        return $result;
43
    }
44
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public function getResolveCallback(string $fieldName): ?callable
50
    {
51
        $resolveMethod = 'resolve' . \ucfirst($fieldName);
52
53
        if (\method_exists($this, $resolveMethod)) {
54
            return [$this, $resolveMethod];
55
        }
56
57
        return null;
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63
    public function getTypeResolver(): ?callable
64
    {
65
        return function ($rootValue, $contextValues, ResolveInfo $info) {
66
            return $this->resolveType($rootValue, $contextValues, $info);
67
        };
68
    }
69
}
70