1111
1212namespace Overblog \GraphQLBundle \Request ;
1313
14+ use GraphQL \Executor \ExecutionResult ;
1415use GraphQL \GraphQL ;
1516use GraphQL \Schema ;
1617use GraphQL \Validator \DocumentValidator ;
2425
2526class Executor
2627{
28+ const DEFAULT_EXECUTOR = 'GraphQL \\GraphQL::executeAndReturnResult ' ;
29+
2730 /**
2831 * @var Schema[]
2932 */
@@ -43,12 +46,35 @@ class Executor
4346 /** @var bool */
4447 private $ hasDebugInfo ;
4548
46- public function __construct (EventDispatcherInterface $ dispatcher = null , $ throwException = false , ErrorHandler $ errorHandler = null , $ hasDebugInfo = false )
49+ /**
50+ * @var callable
51+ */
52+ private $ executor ;
53+
54+ public function __construct (
55+ EventDispatcherInterface $ dispatcher = null ,
56+ $ throwException = false ,
57+ ErrorHandler $ errorHandler = null ,
58+ $ hasDebugInfo = false ,
59+ callable $ executor = null
60+ )
4761 {
4862 $ this ->dispatcher = $ dispatcher ;
4963 $ this ->throwException = (bool ) $ throwException ;
5064 $ this ->errorHandler = $ errorHandler ;
5165 $ hasDebugInfo ? $ this ->enabledDebugInfo () : $ this ->disabledDebugInfo ();
66+ $ this ->executor = $ executor ;
67+ if (null === $ this ->executor ) {
68+ $ this ->executor = self ::DEFAULT_EXECUTOR ;
69+ }
70+
71+ }
72+
73+ public function setExecutor (callable $ executor )
74+ {
75+ $ this ->executor = $ executor ;
76+
77+ return $ this ;
5278 }
5379
5480 public function addSchema ($ name , Schema $ schema )
@@ -116,7 +142,8 @@ public function execute(array $data, array $context = [], $schemaName = null)
116142 $ startTime = microtime (true );
117143 $ startMemoryUsage = memory_get_usage (true );
118144
119- $ executionResult = GraphQL::executeAndReturnResult (
145+ $ executionResult = call_user_func (
146+ $ this ->executor ,
120147 $ schema ,
121148 isset ($ data [ParserInterface::PARAM_QUERY ]) ? $ data [ParserInterface::PARAM_QUERY ] : null ,
122149 $ context ,
@@ -125,6 +152,10 @@ public function execute(array $data, array $context = [], $schemaName = null)
125152 isset ($ data [ParserInterface::PARAM_OPERATION_NAME ]) ? $ data [ParserInterface::PARAM_OPERATION_NAME ] : null
126153 );
127154
155+ if (!is_object ($ executionResult ) || !$ executionResult instanceof ExecutionResult) {
156+ throw new \RuntimeException (sprintf ('Execution result should be an object instantiating "%s". ' , 'GraphQL \\Executor \\ExecutionResult ' ));
157+ }
158+
128159 if ($ this ->hasDebugInfo ()) {
129160 $ executionResult ->extensions ['debug ' ] = [
130161 'executionTime ' => sprintf ('%d ms ' , round (microtime (true ) - $ startTime , 1 ) * 1000 ),
0 commit comments