GraphQL\Executor\Promise\PromiseAdapter::createResolvedPromise PHP Метод

createResolvedPromise() публичный Метод

Creates a full filed Promise for a value if the value is not a promise.
public createResolvedPromise ( mixed $promiseOrValue = null ) : GraphQL\Executor\Promise\Promise
$promiseOrValue mixed
Результат GraphQL\Executor\Promise\Promise a full filed Promise
    public function createResolvedPromise($promiseOrValue = null);

Usage Example

Пример #1
0
 /**
  * This is a small wrapper around completeValue which detects and logs errors
  * in the execution context.
  *
  * @param ExecutionContext $exeContext
  * @param Type $returnType
  * @param $fieldNodes
  * @param ResolveInfo $info
  * @param $path
  * @param $result
  * @return array|null|Promise
  */
 private static function completeValueCatchingError(ExecutionContext $exeContext, Type $returnType, $fieldNodes, ResolveInfo $info, $path, $result)
 {
     // If the field type is non-nullable, then it is resolved without any
     // protection from errors.
     if ($returnType instanceof NonNull) {
         return self::completeValueWithLocatedError($exeContext, $returnType, $fieldNodes, $info, $path, $result);
     }
     // Otherwise, error protection is applied, logging the error and resolving
     // a null value for this field if one is encountered.
     try {
         $completed = self::completeValueWithLocatedError($exeContext, $returnType, $fieldNodes, $info, $path, $result);
         if (self::$promiseAdapter->isPromise($completed)) {
             return $completed->then(null, function ($error) use($exeContext) {
                 $exeContext->addError($error);
                 return self::$promiseAdapter->createResolvedPromise(null);
             });
         }
         return $completed;
     } catch (Error $err) {
         // If `completeValueWithLocatedError` returned abruptly (threw an error), log the error
         // and return null.
         $exeContext->addError($err);
         return null;
     }
 }