Passed
Pull Request — master (#129)
by Christoffer
02:26
created

Execution::execute()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 13
nc 2
nop 7
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace Digia\GraphQL\Execution;
4
5
use Digia\GraphQL\Error\ExecutionException;
6
use Digia\GraphQL\Language\Node\DocumentNode;
7
use Digia\GraphQL\Type\Schema;
8
9
/**
10
 * Class Execution
11
 * @package Digia\GraphQL\Execution
12
 */
13
class Execution implements ExecutionInterface
14
{
15
    /**
16
     * @var ExecutionContextBuilder
17
     */
18
    protected $contextBuilder;
19
20
    /**
21
     * Execution constructor.
22
     * @param $contextBuilder
23
     */
24
    public function __construct(ExecutionContextBuilder $contextBuilder)
25
    {
26
        $this->contextBuilder = $contextBuilder;
27
    }
28
29
    /**
30
     * @param Schema        $schema
31
     * @param DocumentNode  $documentNode
32
     * @param null          $rootValue
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $variableValues is correct as it would always require null to be passed?
Loading history...
Documentation Bug introduced by
Are you sure the doc-type for parameter $operationName is correct as it would always require null to be passed?
Loading history...
Documentation Bug introduced by
Are you sure the doc-type for parameter $rootValue is correct as it would always require null to be passed?
Loading history...
Documentation Bug introduced by
Are you sure the doc-type for parameter $contextValue is correct as it would always require null to be passed?
Loading history...
33
     * @param null          $contextValue
34
     * @param null          $variableValues
35
     * @param null          $operationName
36
     * @param callable|null $fieldResolver
37
     * @return ExecutionResult
38
     */
39
    public function execute(
40
        Schema $schema,
41
        DocumentNode $documentNode,
42
        $rootValue = null,
43
        $contextValue = null,
44
        $variableValues = [],
45
        $operationName = null,
46
        callable $fieldResolver = null
47
    ) : ExecutionResult {
48
        try {
49
            $context = $this->contextBuilder->buildContext(
50
                $schema,
51
                $documentNode,
52
                $rootValue,
53
                $contextValue,
54
                $variableValues,
55
                $operationName,
56
                $fieldResolver
57
            );
58
        } catch (ExecutionException $error) {
59
            return new ExecutionResult(['data' => null], [$error]);
60
        }
61
62
        $data = $context->getExecutionStrategy()->execute();
63
64
        return new ExecutionResult($data, $context->getErrors());
65
    }
66
}
67