/** * @it serializes to include path */ public function testSerializesToIncludePath() { $e = new Error('msg', null, null, null, ['path', 3, 'to', 'field']); $this->assertEquals(['path', 3, 'to', 'field'], $e->path); $this->assertEquals(['message' => 'msg', 'path' => ['path', 3, 'to', 'field']], $e->toSerializableArray()); }
/** * 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); } }
/** * This is a small wrapper around completeValue which annotates errors with * location information. * * @param ExecutionContext $exeContext * @param Type $returnType * @param $fieldASTs * @param ResolveInfo $info * @param $path * @param $result * @return array|null * @throws Error */ static function completeValueWithLocatedError(ExecutionContext $exeContext, Type $returnType, $fieldASTs, ResolveInfo $info, $path, $result) { try { return self::completeValue($exeContext, $returnType, $fieldASTs, $info, $path, $result); } catch (\Exception $error) { throw Error::createLocatedError($error, $fieldASTs, $path); } }
/** * @it does not allow unknown types to be used as values */ public function testDoesNotAllowUnknownTypesToBeUsedAsValues() { $doc = ' query q($input: UnknownType!) { fieldWithObjectInput(input: $input) } '; $ast = Parser::parse($doc); $vars = ['input' => 'whoknows']; try { Executor::execute($this->schema(), $ast, null, null, $vars); $this->fail('Expected exception not thrown'); } catch (Error $error) { $expected = FormattedError::create('Variable "$input" expected value of type "UnknownType!" which ' . 'cannot be used as an input type.', [new SourceLocation(2, 17)]); $this->assertEquals($expected, Error::formatError($error)); } }
/** * @param Source $source * @param int $position * @param string $description */ public function __construct(Source $source, $position, $description) { $location = $source->getLocation($position); $syntaxError = "Syntax Error {$source->name} ({$location->line}:{$location->column}) {$description}\n\n" . self::highlightSourceAtLocation($source, $location); parent::__construct($syntaxError, null, $source, [$position]); }
/** * @param Error $error * @return array */ public static function formatError(Error $error) { return $error->toSerializableArray(); }