Completed
Pull Request — master (#18)
by Quang
03:15
created

ExecutorExecutionStrategy::execute()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 14
nc 4
nop 0
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace Digia\GraphQL\Execution;
4
5
use Digia\GraphQL\Error\GraphQLError;
6
7
class ExecutorExecutionStrategy extends ExecutionStrategy
8
{
9
10
    /**
11
     * @return ?array
12
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment ?array at position 0 could not be parsed: Unknown type name '?array' at position 0 in ?array.
Loading history...
13
    function execute(): ?array
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
14
    {
15
        $operation = $this->context->getOperation()->getOperation();
16
        $schema    = $this->context->getSchema();
17
18
        $objectType = ($operation === 'mutation')
19
            ? $schema->getMutation()
20
            : $schema->getQuery();
21
22
        $fields = $this->collectFields($objectType, $this->operation->getSelectionSet(), new \ArrayObject(), new \ArrayObject());
23
        $path   = [];
24
25
        try {
26
            $data = $this->executeFields($objectType, $this->rootValue, $path, $fields);
27
        } catch (\Exception $ex) {
28
            $this->context->addError(
29
                new GraphQLError($ex->getMessage())
30
            );
31
            return null;
32
        }
33
34
        return $data;
35
    }
36
}
37