Completed
Pull Request — master (#49)
by Quang
02:36 queued 24s
created

Execution::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
namespace Digia\GraphQL\Execution;
4
5
use Digia\GraphQL\Error\ExecutionException;
6
use Digia\GraphQL\Language\AST\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
     * @param Schema        $schema
17
     * @param DocumentNode  $documentNode
18
     * @param null          $rootValue
0 ignored issues
show
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 $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 $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...
19
     * @param null          $contextValue
20
     * @param null          $variableValues
21
     * @param null          $operationName
22
     * @param callable|null $fieldResolver
23
     * @return ExecutionResult
24
     */
25
    public function execute(
26
        Schema $schema,
27
        DocumentNode $documentNode,
28
        $rootValue = null,
29
        $contextValue = null,
30
        $variableValues = [],
31
        $operationName = null,
32
        callable $fieldResolver = null
33
    ) : ExecutionResult {
34
        try {
35
            //@TODO Get context builder from container?
36
            $contextBuilder = new ExecutionContextBuilder();
37
38
            $context = $contextBuilder->buildContext(
39
                $schema,
40
                $documentNode,
41
                $rootValue,
42
                $contextValue,
43
                $variableValues,
44
                $operationName,
45
                $fieldResolver
46
            );
47
        } catch (ExecutionException $error) {
48
            return new ExecutionResult(['data' => null], [$error]);
49
        }
50
51
        $data = $context->getExecutionStrategy()->execute();
52
53
        return new ExecutionResult($data, $context->getErrors());
54
    }
55
}
56