setRawVariableValues($variableValues); $validationErrors = DocumentValidator::validate($schema, $documentNode, $validationRules); if (!empty($validationErrors)) { return new ExecutionResult(null, $validationErrors); } else { return Executor::execute( $schema, $documentNode, $rootValue, $contextValue, $variableValues, $operationName, $fieldResolver, $promiseAdapter ); } } catch (Error $e) { return new ExecutionResult(null, [$e]); } } /** * @deprecated Use executeQuery()->toArray() instead * * @param \GraphQL\Type\Schema $schema * @param string|DocumentNode $source * @param mixed $rootValue * @param mixed $contextValue * @param array|null $variableValues * @param string|null $operationName * @param callable $fieldResolver * @param array $validationRules * @param PromiseAdapter $promiseAdapter * @return Promise|array */ public static function execute( \GraphQL\Type\Schema $schema, $source, $rootValue = null, $contextValue = null, $variableValues = null, $operationName = null, callable $fieldResolver = null, array $validationRules = null, PromiseAdapter $promiseAdapter = null ) { $result = self::executeQuery( $schema, $source, $rootValue, $contextValue, $variableValues, $operationName, $fieldResolver, $validationRules, $promiseAdapter ); if ($result instanceof ExecutionResult) { return $result->toArray(); } if ($result instanceof Promise) { return $result->then(function(ExecutionResult $executionResult) { return $executionResult->toArray(); }); } throw new InvariantViolation("Unexpected execution result"); } /** * @deprecated renamed to executeQuery() * * @param \GraphQL\Type\Schema $schema * @param string|DocumentNode $source * @param mixed $rootValue * @param mixed $contextValue * @param array|null $variableValues * @param string|null $operationName * @param callable $fieldResolver * @param array $validationRules * @param PromiseAdapter $promiseAdapter * * @return ExecutionResult|Promise */ public static function executeAndReturnResult( \GraphQL\Type\Schema $schema, $source, $rootValue = null, $contextValue = null, $variableValues = null, $operationName = null, callable $fieldResolver = null, array $validationRules = null, PromiseAdapter $promiseAdapter = null ) { return self::executeQuery( $schema, $source, $rootValue, $contextValue, $variableValues, $operationName, $fieldResolver, $validationRules, $promiseAdapter ); } /** * Returns directives defined in GraphQL spec * * @return Directive[] */ public static function getInternalDirectives() { return array_values(Directive::getInternalDirectives()); } /** * Returns types defined in GraphQL spec * * @return Type[] */ public static function getInternalTypes() { return Type::getInternalTypes(); } /** * @param callable $fn */ public static function setDefaultFieldResolver(callable $fn) { Executor::setDefaultFieldResolver($fn); } /** * @param PromiseAdapter|null $promiseAdapter */ public static function setPromiseAdapter(PromiseAdapter $promiseAdapter = null) { Executor::setPromiseAdapter($promiseAdapter); } }