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

ExecutorExecutionStrategy   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 22 3
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