Skip to content

Commit 06c400a

Browse files
committed
Returned reference executor implementation back, updated tests, so both executors pass
1 parent 8b4c030 commit 06c400a

13 files changed

+1625
-172
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
composer.phar
1+
.phpcs-cache
22
composer.lock
3+
composer.phar
34
phpcs.xml
45
vendor/

src/Executor/ExecutionContext.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace GraphQL\Executor;
6+
7+
use GraphQL\Error\Error;
8+
use GraphQL\Executor\Promise\PromiseAdapter;
9+
use GraphQL\Language\AST\FragmentDefinitionNode;
10+
use GraphQL\Language\AST\OperationDefinitionNode;
11+
use GraphQL\Type\Schema;
12+
13+
/**
14+
* Data that must be available at all points during query execution.
15+
*
16+
* Namely, schema of the type system that is currently executing,
17+
* and the fragments defined in the query document
18+
*
19+
* @internal
20+
*/
21+
class ExecutionContext
22+
{
23+
/** @var Schema */
24+
public $schema;
25+
26+
/** @var FragmentDefinitionNode[] */
27+
public $fragments;
28+
29+
/** @var mixed */
30+
public $rootValue;
31+
32+
/** @var mixed */
33+
public $contextValue;
34+
35+
/** @var OperationDefinitionNode */
36+
public $operation;
37+
38+
/** @var mixed[] */
39+
public $variableValues;
40+
41+
/** @var callable */
42+
public $fieldResolver;
43+
44+
/** @var Error[] */
45+
public $errors;
46+
47+
/** @var PromiseAdapter */
48+
public $promises;
49+
50+
public function __construct(
51+
$schema,
52+
$fragments,
53+
$root,
54+
$contextValue,
55+
$operation,
56+
$variables,
57+
$errors,
58+
$fieldResolver,
59+
$promiseAdapter
60+
) {
61+
$this->schema = $schema;
62+
$this->fragments = $fragments;
63+
$this->rootValue = $root;
64+
$this->contextValue = $contextValue;
65+
$this->operation = $operation;
66+
$this->variableValues = $variables;
67+
$this->errors = $errors ?: [];
68+
$this->fieldResolver = $fieldResolver;
69+
$this->promises = $promiseAdapter;
70+
}
71+
72+
public function addError(Error $error)
73+
{
74+
$this->errors[] = $error;
75+
76+
return $this;
77+
}
78+
}

src/Executor/Executor.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,9 @@ class Executor
2828
/** @var callable */
2929
private static $implementationFactory = [CoroutineExecutor::class, 'create'];
3030

31-
/**
32-
* @return PromiseAdapter
33-
*/
34-
public static function getPromiseAdapter()
35-
{
36-
return self::$defaultPromiseAdapter ?: (self::$defaultPromiseAdapter = new SyncPromiseAdapter());
37-
}
38-
39-
public static function setPromiseAdapter(?PromiseAdapter $defaultPromiseAdapter = null)
31+
public static function getDefaultFieldResolver() : callable
4032
{
41-
self::$defaultPromiseAdapter = $defaultPromiseAdapter;
33+
return self::$defaultFieldResolver;
4234
}
4335

4436
/**
@@ -50,15 +42,27 @@ public static function setDefaultFieldResolver(callable $fieldResolver)
5042
}
5143

5244
/**
53-
* @return callable
45+
* @return PromiseAdapter
5446
*/
55-
public static function getImplementationFactory()
47+
public static function getPromiseAdapter() : PromiseAdapter
48+
{
49+
return self::$defaultPromiseAdapter ?: (self::$defaultPromiseAdapter = new SyncPromiseAdapter());
50+
}
51+
52+
public static function setPromiseAdapter(?PromiseAdapter $defaultPromiseAdapter = null)
53+
{
54+
self::$defaultPromiseAdapter = $defaultPromiseAdapter;
55+
}
56+
57+
public static function getImplementationFactory() : callable
5658
{
5759
return self::$implementationFactory;
5860
}
5961

6062
/**
61-
* Custom executor implementation.
63+
* Custom executor implementation factory.
64+
*
65+
* Will be called with as
6266
*/
6367
public static function setImplementationFactory(callable $implementationFactory)
6468
{
@@ -134,7 +138,7 @@ public static function promiseToExecute(
134138
) {
135139
$factory = self::$implementationFactory;
136140

137-
/** @var Implementation $executor */
141+
/** @var ExecutorImplementation $executor */
138142
$executor = $factory(
139143
$promiseAdapter,
140144
$schema,

src/Executor/Implementation.php renamed to src/Executor/ExecutorImplementation.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
/**
1010
* Executor implementation.
1111
*/
12-
interface Implementation
12+
interface ExecutorImplementation
1313
{
1414
/**
1515
* Returns promise of {@link ExecutionResult}. Promise should always resolve, never reject.
16-
*
1716
*/
1817
public function doExecute() : Promise;
1918
}

0 commit comments

Comments
 (0)