config = $config; $this->helper = new Helper(); } /** * Executes GraphQL operation with given server configuration and returns execution result * (or promise when promise adapter is different from SyncPromiseAdapter) * * @param ServerRequestInterface $request * @return ExecutionResult|ExecutionResult[]|Promise */ public function executePsrRequest(ServerRequestInterface $request) { $parsedBody = $this->helper->parsePsrRequest($request); return $this->executeRequest($parsedBody); } /** * Executes GraphQL operation with given server configuration and returns execution result * (or promise when promise adapter is different from SyncPromiseAdapter) * * @param OperationParams|OperationParams[] $parsedBody * @return ExecutionResult|ExecutionResult[]|Promise * @throws InvariantViolation */ public function executeRequest($parsedBody = null) { if (null === $parsedBody) { $parsedBody = $this->helper->parseHttpRequest(); } if (is_array($parsedBody)) { return $this->helper->executeBatch($this->config, $parsedBody); } else { return $this->helper->executeOperation($this->config, $parsedBody); } } /** * @param ServerRequestInterface $request * @param ResponseInterface $response * @param StreamInterface $writableBodyStream * @return ResponseInterface|Promise */ public function processPsrRequest( ServerRequestInterface $request, ResponseInterface $response, StreamInterface $writableBodyStream ) { $result = $this->executePsrRequest($request); return $this->helper->toPsrResponse($result, $response, $writableBodyStream); } /** * @param OperationParams|OperationParams[] $parsedBody * @param bool $exitWhenDone */ public function processRequest($parsedBody = null, $exitWhenDone = false) { $result = $this->executeRequest($parsedBody); $this->helper->sendResponse($result, $exitWhenDone); } }