GraphQL\Error\Error::createLocatedError PHP Méthode

createLocatedError() public static méthode

Given an arbitrary Error, presumably thrown while attempting to execute a GraphQL operation, produce a new GraphQLError aware of the location in the document responsible for the original Error.
public static createLocatedError ( $error, array | null $nodes = null, array | null $path = null ) : Error
$error
$nodes array | null
$path array | null
Résultat Error
    public static function createLocatedError($error, $nodes = null, $path = null)
    {
        if ($error instanceof self && $error->path) {
            return $error;
        }
        $source = $positions = $originalError = null;
        if ($error instanceof self) {
            $message = $error->getMessage();
            $originalError = $error;
            $nodes = $error->nodes ?: $nodes;
            $source = $error->source;
            $positions = $error->positions;
        } else {
            if ($error instanceof \Exception) {
                $message = $error->getMessage();
                $originalError = $error;
            } else {
                $message = (string) $error;
            }
        }
        return new static($message ?: 'An unknown error occurred.', $nodes, $source, $positions, $path, $originalError);
    }

Usage Example

Exemple #1
0
 /**
  * This is a small wrapper around completeValue which annotates errors with
  * location information.
  *
  * @param ExecutionContext $exeContext
  * @param Type $returnType
  * @param $fieldNodes
  * @param ResolveInfo $info
  * @param $path
  * @param $result
  * @return array|null|Promise
  * @throws Error
  */
 public static function completeValueWithLocatedError(ExecutionContext $exeContext, Type $returnType, $fieldNodes, ResolveInfo $info, $path, $result)
 {
     try {
         $completed = self::completeValue($exeContext, $returnType, $fieldNodes, $info, $path, $result);
         if (self::$promiseAdapter->isPromise($completed)) {
             return $completed->then(null, function ($error) use($fieldNodes, $path) {
                 return self::$promiseAdapter->createRejectedPromise(Error::createLocatedError($error, $fieldNodes, $path));
             });
         }
         return $completed;
     } catch (\Exception $error) {
         throw Error::createLocatedError($error, $fieldNodes, $path);
     }
 }
All Usage Examples Of GraphQL\Error\Error::createLocatedError