errors`. * * @param mixed|null $rootValue * @param mixed|null $contextValue * @param array|ArrayAccess|null $variableValues * @param string|null $operationName * * @return ExecutionResult|Promise * * @api */ public static function execute( Schema $schema, DocumentNode $documentNode, $rootValue = null, $contextValue = null, $variableValues = null, $operationName = null, ?callable $fieldResolver = null ) { // TODO: deprecate (just always use SyncAdapter here) and have `promiseToExecute()` for other cases $promiseAdapter = static::getPromiseAdapter(); $result = static::promiseToExecute( $promiseAdapter, $schema, $documentNode, $rootValue, $contextValue, $variableValues, $operationName, $fieldResolver ); if ($promiseAdapter instanceof SyncPromiseAdapter) { $result = $promiseAdapter->wait($result); } return $result; } /** * Same as execute(), but requires promise adapter and returns a promise which is always * fulfilled with an instance of ExecutionResult and never rejected. * * Useful for async PHP platforms. * * @param mixed|null $rootValue * @param mixed|null $contextValue * @param array|null $variableValues * @param string|null $operationName * * @return Promise * * @api */ public static function promiseToExecute( PromiseAdapter $promiseAdapter, Schema $schema, DocumentNode $documentNode, $rootValue = null, $contextValue = null, $variableValues = null, $operationName = null, ?callable $fieldResolver = null ) { $factory = self::$implementationFactory; /** @var ExecutorImplementation $executor */ $executor = $factory( $promiseAdapter, $schema, $documentNode, $rootValue, $contextValue, $variableValues, $operationName, $fieldResolver ?? self::$defaultFieldResolver ); return $executor->doExecute(); } /** * If a resolve function is not given, then a default resolve behavior is used * which takes the property of the root value of the same name as the field * and returns it as the result, or if it's a function, returns the result * of calling that function while passing along args and context. * * @param mixed $objectValue * @param array $args * @param mixed|null $contextValue * * @return mixed|null */ public static function defaultFieldResolver($objectValue, $args, $contextValue, ResolveInfo $info) { $fieldName = $info->fieldName; $property = null; if (is_array($objectValue) || $objectValue instanceof ArrayAccess) { if (isset($objectValue[$fieldName])) { $property = $objectValue[$fieldName]; } } elseif (is_object($objectValue)) { if (isset($objectValue->{$fieldName})) { $property = $objectValue->{$fieldName}; } } return $property instanceof Closure ? $property($objectValue, $args, $contextValue, $info) : $property; } }