Throwing GraphQL\Error\Error vs GraphQL\Error\UserError from type definitions

This commit is contained in:
Vladimir Razuvaev 2017-07-19 19:39:10 +07:00
parent e6e531b88b
commit 08a68d4857
5 changed files with 10 additions and 10 deletions

View File

@ -1,8 +1,8 @@
<?php <?php
namespace GraphQL\Type\Definition; namespace GraphQL\Type\Definition;
use GraphQL\Error\Error;
use GraphQL\Error\InvariantViolation; use GraphQL\Error\InvariantViolation;
use GraphQL\Error\UserError;
use GraphQL\Language\AST\FloatValueNode; use GraphQL\Language\AST\FloatValueNode;
use GraphQL\Language\AST\IntValueNode; use GraphQL\Language\AST\IntValueNode;
use GraphQL\Utils\Utils; use GraphQL\Utils\Utils;
@ -63,7 +63,7 @@ values as specified by
$isInput ? Utils::printSafeJson($value) : Utils::printSafe($value) $isInput ? Utils::printSafeJson($value) : Utils::printSafe($value)
); );
} }
throw ($isInput ? new UserError($err) : new InvariantViolation($err)); throw ($isInput ? new Error($err) : new InvariantViolation($err));
} }
/** /**

View File

@ -1,8 +1,8 @@
<?php <?php
namespace GraphQL\Type\Definition; namespace GraphQL\Type\Definition;
use GraphQL\Error\Error;
use GraphQL\Error\InvariantViolation; use GraphQL\Error\InvariantViolation;
use GraphQL\Error\UserError;
use GraphQL\Language\AST\IntValueNode; use GraphQL\Language\AST\IntValueNode;
use GraphQL\Language\AST\StringValueNode; use GraphQL\Language\AST\StringValueNode;
use GraphQL\Utils\Utils; use GraphQL\Utils\Utils;
@ -65,7 +65,7 @@ When expected as an input type, any string (such as `"4"`) or integer
return 'null'; return 'null';
} }
if (!is_scalar($value)) { if (!is_scalar($value)) {
throw new UserError("ID type cannot represent non scalar value: " . Utils::printSafeJson($value)); throw new Error("ID type cannot represent non scalar value: " . Utils::printSafeJson($value));
} }
return (string) $value; return (string) $value;
} }

View File

@ -1,8 +1,8 @@
<?php <?php
namespace GraphQL\Type\Definition; namespace GraphQL\Type\Definition;
use GraphQL\Error\Error;
use GraphQL\Error\InvariantViolation; use GraphQL\Error\InvariantViolation;
use GraphQL\Error\UserError;
use GraphQL\Language\AST\IntValueNode; use GraphQL\Language\AST\IntValueNode;
use GraphQL\Utils\Utils; use GraphQL\Utils\Utils;
@ -57,7 +57,7 @@ values. Int can represent values between -(2^31) and 2^31 - 1. ';
*/ */
private function coerceInt($value, $isInput) private function coerceInt($value, $isInput)
{ {
$errClass = $isInput ? UserError::class : InvariantViolation::class; $errClass = $isInput ? Error::class : InvariantViolation::class;
if ($value === '') { if ($value === '') {
throw new $errClass( throw new $errClass(

View File

@ -1,7 +1,7 @@
<?php <?php
namespace GraphQL\Type\Definition; namespace GraphQL\Type\Definition;
use GraphQL\Error\Error;
use GraphQL\Error\InvariantViolation; use GraphQL\Error\InvariantViolation;
use GraphQL\Error\UserError;
use GraphQL\Utils\Utils; use GraphQL\Utils\Utils;
@ -133,7 +133,7 @@ class ObjectType extends Type implements OutputType, CompositeType
$this->getFields(); $this->getFields();
} }
if (!isset($this->fields[$name])) { if (!isset($this->fields[$name])) {
throw new UserError(sprintf("Field '%s' is not defined for type '%s'", $name, $this->name)); throw new Error(sprintf("Field '%s' is not defined for type '%s'", $name, $this->name));
} }
return $this->fields[$name]; return $this->fields[$name];
} }

View File

@ -1,8 +1,8 @@
<?php <?php
namespace GraphQL\Type\Definition; namespace GraphQL\Type\Definition;
use GraphQL\Error\Error;
use GraphQL\Error\InvariantViolation; use GraphQL\Error\InvariantViolation;
use GraphQL\Error\UserError;
use GraphQL\Language\AST\StringValueNode; use GraphQL\Language\AST\StringValueNode;
use GraphQL\Utils\Utils; use GraphQL\Utils\Utils;
@ -62,7 +62,7 @@ represent free-form human-readable text.';
return 'null'; return 'null';
} }
if (!is_scalar($value)) { if (!is_scalar($value)) {
throw new UserError("String cannot represent non scalar value: " . Utils::printSafe($value)); throw new Error("String cannot represent non scalar value: " . Utils::printSafe($value));
} }
return (string) $value; return (string) $value;
} }