diff --git a/src/Type/Definition/BooleanType.php b/src/Type/Definition/BooleanType.php index 3446094..262b274 100644 --- a/src/Type/Definition/BooleanType.php +++ b/src/Type/Definition/BooleanType.php @@ -7,6 +7,8 @@ class BooleanType extends ScalarType { public $name = Type::BOOLEAN; + public $description = 'The `Boolean` scalar type represents `true` or `false`.'; + public function serialize($value) { return !!$value; diff --git a/src/Type/Definition/FloatType.php b/src/Type/Definition/FloatType.php index da58b47..d40bf6b 100644 --- a/src/Type/Definition/FloatType.php +++ b/src/Type/Definition/FloatType.php @@ -8,6 +8,11 @@ class FloatType extends ScalarType { public $name = Type::FLOAT; + public $description = + 'The `Float` scalar type represents signed double-precision fractional ' . + 'values as specified by ' . + '[IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point). '; + public function serialize($value) { return $this->coerceFloat($value); diff --git a/src/Type/Definition/IDType.php b/src/Type/Definition/IDType.php index e6f1deb..ead6ea4 100644 --- a/src/Type/Definition/IDType.php +++ b/src/Type/Definition/IDType.php @@ -8,6 +8,13 @@ class IDType extends ScalarType { public $name = 'ID'; + public $description = + 'The `ID` scalar type represents a unique identifier, often used to ' . + 'refetch an object or as key for a cache. The ID type appears in a JSON ' . + 'response as a String; however, it is not intended to be human-readable. ' . + 'When expected as an input type, any string (such as `"4"`) or integer ' . + '(such as `4`) input value will be accepted as an ID.'; + public function serialize($value) { return (string) $value; diff --git a/src/Type/Definition/IntType.php b/src/Type/Definition/IntType.php index 8370e53..f21ae1c 100644 --- a/src/Type/Definition/IntType.php +++ b/src/Type/Definition/IntType.php @@ -6,8 +6,20 @@ use GraphQL\Language\AST\Value; class IntType extends ScalarType { + // As per the GraphQL Spec, Integers are only treated as valid when a valid + // 32-bit signed integer, providing the broadest support across platforms. + // + // n.b. JavaScript's integers are safe between -(2^53 - 1) and 2^53 - 1 because + // they are internally represented as IEEE 754 doubles. + const MAX_INT = 2147483647; + const MIN_INT = -2147483648; + public $name = Type::INT; + public $description = + 'The `Int` scalar type represents non-fractional signed whole numeric ' . + 'values. Int can represent values between -(2^31) and 2^31 - 1. '; + public function serialize($value) { return $this->coerceInt($value); @@ -23,7 +35,7 @@ class IntType extends ScalarType if (false === $value || true === $value) { return (int) $value; } - if (is_numeric($value) && $value <= PHP_INT_MAX && $value >= -1 * PHP_INT_MAX) { + if (is_numeric($value) && $value <= self::MAX_INT && $value >= self::MIN_INT) { return (int) $value; } return null; @@ -33,7 +45,7 @@ class IntType extends ScalarType { if ($ast instanceof IntValue) { $val = (int) $ast->value; - if ($ast->value === (string) $val) { + if ($ast->value === (string) $val && self::MIN_INT <= $val && $val <= self::MAX_INT) { return $val; } } diff --git a/src/Type/Definition/StringType.php b/src/Type/Definition/StringType.php index cccea49..9d51969 100644 --- a/src/Type/Definition/StringType.php +++ b/src/Type/Definition/StringType.php @@ -7,6 +7,11 @@ class StringType extends ScalarType { public $name = Type::STRING; + public $description = + 'The `String` scalar type represents textual data, represented as UTF-8 ' . + 'character sequences. The String type is most often used by GraphQL to ' . + 'represent free-form human-readable text.'; + public function serialize($value) { return $this->parseValue($value);