1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the OverblogGraphQLBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Overblog <http://github.com/overblog/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Overblog\GraphQLBundle\Executor; |
13
|
|
|
|
14
|
|
|
use GraphQL\Executor\ExecutionResult; |
15
|
|
|
use GraphQL\Executor\Promise\Promise; |
16
|
|
|
use GraphQL\Executor\Promise\PromiseAdapter; |
17
|
|
|
use GraphQL\GraphQL; |
18
|
|
|
use GraphQL\Type\Schema; |
19
|
|
|
|
20
|
|
|
class Executor implements ExecutorInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var PromiseAdapter |
24
|
|
|
*/ |
25
|
|
|
private $promiseAdapter; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param Schema $schema |
29
|
|
|
* @param string $requestString |
30
|
|
|
* @param null|array $rootValue |
31
|
|
|
* @param null|array $contextValue |
32
|
|
|
* @param null|array $variableValues |
33
|
|
|
* @param null|string $operationName |
34
|
|
|
* |
35
|
|
|
* @return ExecutionResult|Promise |
36
|
|
|
*/ |
37
|
59 |
|
public function execute(Schema $schema, $requestString, $rootValue = null, $contextValue = null, $variableValues = null, $operationName = null) |
38
|
|
|
{ |
39
|
59 |
|
$args = func_get_args(); |
40
|
|
|
|
41
|
59 |
|
if (null === $this->promiseAdapter) { |
42
|
2 |
|
$method = 'executeQuery'; |
43
|
2 |
|
} else { |
44
|
57 |
|
array_unshift($args, $this->promiseAdapter); |
45
|
57 |
|
$method = 'promiseToExecute'; |
46
|
|
|
} |
47
|
|
|
|
48
|
59 |
|
return call_user_func_array(sprintf('\%s::%s', GraphQL::class, $method), $args); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param PromiseAdapter|null $promiseAdapter |
53
|
|
|
*/ |
54
|
61 |
|
public function setPromiseAdapter(PromiseAdapter $promiseAdapter = null) |
55
|
|
|
{ |
56
|
61 |
|
$this->promiseAdapter = $promiseAdapter; |
57
|
61 |
|
} |
58
|
|
|
} |
59
|
|
|
|