From 81986145fe880096a277e4852203a28563a0d4d1 Mon Sep 17 00:00:00 2001 From: Vladimir Razuvaev Date: Wed, 19 Jul 2017 19:55:22 +0700 Subject: [PATCH] Server: moving things around to simplify --- src/Server/Helper.php | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Server/Helper.php b/src/Server/Helper.php index 616794b..1508496 100644 --- a/src/Server/Helper.php +++ b/src/Server/Helper.php @@ -35,14 +35,7 @@ class Helper public function executeOperation(ServerConfig $config, OperationParams $op) { $promiseAdapter = $config->getPromiseAdapter() ?: Executor::getPromiseAdapter(); - - $errors = $this->validateOperationParams($op); - - if (!empty($errors)) { - $result = $promiseAdapter->createFulfilled(new ExecutionResult(null, $errors)); - } else { - $result = $this->promiseToExecuteOperation($promiseAdapter, $config, $op); - } + $result = $this->promiseToExecuteOperation($promiseAdapter, $config, $op); if ($promiseAdapter instanceof SyncPromiseAdapter) { $result = $promiseAdapter->wait($result); @@ -65,12 +58,7 @@ class Helper $result = []; foreach ($operations as $operation) { - $errors = $this->validateOperationParams($operation); - if (!empty($errors)) { - $result[] = $promiseAdapter->createFulfilled(new ExecutionResult(null, $errors)); - } else { - $result[] = $this->promiseToExecuteOperation($promiseAdapter, $config, $operation); - } + $result[] = $this->promiseToExecuteOperation($promiseAdapter, $config, $operation); } $result = $promiseAdapter->all($result); @@ -91,6 +79,14 @@ class Helper private function promiseToExecuteOperation(PromiseAdapter $promiseAdapter, ServerConfig $config, OperationParams $op) { try { + $errors = $this->validateOperationParams($op); + + if (!empty($errors)) { + return $promiseAdapter->createFulfilled( + new ExecutionResult(null, $errors) + ); + } + $doc = $op->queryId ? static::loadPersistedQuery($config, $op) : $op->query; if (!$doc instanceof DocumentNode) {