Fix CS in src/Type

This commit is contained in:
Simon Podlipsky 2018-09-26 10:51:11 +02:00
parent 7ba98ce773
commit 18a5639cb7
No known key found for this signature in database
GPG Key ID: 725C2BD962B42663
29 changed files with 277 additions and 116 deletions

View File

@ -17,6 +17,7 @@ interface AbstractType
* *
* @param object $objectValue * @param object $objectValue
* @param mixed[] $context * @param mixed[] $context
*
* @return mixed * @return mixed
*/ */
public function resolveType($objectValue, $context, ResolveInfo $info); public function resolveType($objectValue, $context, ResolveInfo $info);

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Type\Definition; namespace GraphQL\Type\Definition;
use Exception;
use GraphQL\Error\Error; use GraphQL\Error\Error;
use GraphQL\Language\AST\BooleanValueNode; use GraphQL\Language\AST\BooleanValueNode;
use GraphQL\Language\AST\Node; use GraphQL\Language\AST\Node;
@ -23,6 +24,7 @@ class BooleanType extends ScalarType
/** /**
* @param mixed $value * @param mixed $value
*
* @return bool * @return bool
*/ */
public function serialize($value) public function serialize($value)
@ -32,7 +34,9 @@ class BooleanType extends ScalarType
/** /**
* @param mixed $value * @param mixed $value
*
* @return bool * @return bool
*
* @throws Error * @throws Error
*/ */
public function parseValue($value) public function parseValue($value)
@ -47,8 +51,10 @@ class BooleanType extends ScalarType
/** /**
* @param Node $valueNode * @param Node $valueNode
* @param mixed[]|null $variables * @param mixed[]|null $variables
*
* @return bool|null * @return bool|null
* @throws \Exception *
* @throws Exception
*/ */
public function parseLiteral($valueNode, ?array $variables = null) public function parseLiteral($valueNode, ?array $variables = null)
{ {
@ -57,6 +63,6 @@ class BooleanType extends ScalarType
} }
// Intentionally without message, as all information already in wrapped Exception // Intentionally without message, as all information already in wrapped Exception
throw new \Exception(); throw new Exception();
} }
} }

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Type\Definition; namespace GraphQL\Type\Definition;
use Exception;
use GraphQL\Language\AST\Node; use GraphQL\Language\AST\Node;
use GraphQL\Utils\AST; use GraphQL\Utils\AST;
use GraphQL\Utils\Utils; use GraphQL\Utils\Utils;
@ -18,6 +19,7 @@ class CustomScalarType extends ScalarType
{ {
/** /**
* @param mixed $value * @param mixed $value
*
* @return mixed * @return mixed
*/ */
public function serialize($value) public function serialize($value)
@ -27,6 +29,7 @@ class CustomScalarType extends ScalarType
/** /**
* @param mixed $value * @param mixed $value
*
* @return mixed * @return mixed
*/ */
public function parseValue($value) public function parseValue($value)
@ -41,8 +44,10 @@ class CustomScalarType extends ScalarType
/** /**
* @param Node $valueNode * @param Node $valueNode
* @param mixed[]|null $variables * @param mixed[]|null $variables
*
* @return mixed * @return mixed
* @throws \Exception *
* @throws Exception
*/ */
public function parseLiteral(/* GraphQL\Language\AST\ValueNode */ public function parseLiteral(/* GraphQL\Language\AST\ValueNode */
$valueNode, $valueNode,

View File

@ -41,7 +41,6 @@ class Directive
public $config; public $config;
/** /**
*
* @param mixed[] $config * @param mixed[] $config
*/ */
public function __construct(array $config) public function __construct(array $config)

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace GraphQL\Type\Definition; namespace GraphQL\Type\Definition;
use ArrayObject;
use Exception;
use GraphQL\Error\Error; use GraphQL\Error\Error;
use GraphQL\Error\InvariantViolation; use GraphQL\Error\InvariantViolation;
use GraphQL\Language\AST\EnumTypeDefinitionNode; use GraphQL\Language\AST\EnumTypeDefinitionNode;
@ -54,6 +56,7 @@ class EnumType extends Type implements InputType, OutputType, LeafType, NamedTyp
/** /**
* @param string|mixed[] $name * @param string|mixed[] $name
*
* @return EnumValueDefinition|null * @return EnumValueDefinition|null
*/ */
public function getValue($name) public function getValue($name)
@ -73,7 +76,7 @@ class EnumType extends Type implements InputType, OutputType, LeafType, NamedTyp
private function getNameLookup() private function getNameLookup()
{ {
if (! $this->nameLookup) { if (! $this->nameLookup) {
$lookup = new \ArrayObject(); $lookup = new ArrayObject();
foreach ($this->getValues() as $value) { foreach ($this->getValues() as $value) {
$lookup[$value->name] = $value; $lookup[$value->name] = $value;
} }
@ -123,7 +126,9 @@ class EnumType extends Type implements InputType, OutputType, LeafType, NamedTyp
/** /**
* @param mixed $value * @param mixed $value
*
* @return mixed * @return mixed
*
* @throws Error * @throws Error
*/ */
public function serialize($value) public function serialize($value)
@ -154,7 +159,9 @@ class EnumType extends Type implements InputType, OutputType, LeafType, NamedTyp
/** /**
* @param mixed $value * @param mixed $value
*
* @return mixed * @return mixed
*
* @throws Error * @throws Error
*/ */
public function parseValue($value) public function parseValue($value)
@ -170,8 +177,10 @@ class EnumType extends Type implements InputType, OutputType, LeafType, NamedTyp
/** /**
* @param Node $valueNode * @param Node $valueNode
* @param mixed[]|null $variables * @param mixed[]|null $variables
*
* @return null * @return null
* @throws \Exception *
* @throws Exception
*/ */
public function parseLiteral($valueNode, ?array $variables = null) public function parseLiteral($valueNode, ?array $variables = null)
{ {
@ -186,7 +195,7 @@ class EnumType extends Type implements InputType, OutputType, LeafType, NamedTyp
} }
// Intentionally without message, as all information already in wrapped Exception // Intentionally without message, as all information already in wrapped Exception
throw new \Exception(); throw new Exception();
} }
/** /**

View File

@ -38,7 +38,6 @@ class FieldArgument
private $defaultValueExists = false; private $defaultValueExists = false;
/** /**
*
* @param mixed[] $def * @param mixed[] $def
*/ */
public function __construct(array $def) public function __construct(array $def)
@ -68,6 +67,7 @@ class FieldArgument
/** /**
* @param mixed[] $config * @param mixed[] $config
*
* @return FieldArgument[] * @return FieldArgument[]
*/ */
public static function createMap(array $config) public static function createMap(array $config)

View File

@ -65,7 +65,6 @@ class FieldDefinition
private $complexityFn; private $complexityFn;
/** /**
*
* @param mixed[] $config * @param mixed[] $config
*/ */
protected function __construct(array $config) protected function __construct(array $config)
@ -140,6 +139,7 @@ class FieldDefinition
/** /**
* @param mixed[] $field * @param mixed[] $field
*
* @return FieldDefinition * @return FieldDefinition
*/ */
public static function create($field) public static function create($field)
@ -149,6 +149,7 @@ class FieldDefinition
/** /**
* @param int $childrenComplexity * @param int $childrenComplexity
*
* @return mixed * @return mixed
*/ */
public static function defaultComplexity($childrenComplexity) public static function defaultComplexity($childrenComplexity)
@ -158,6 +159,7 @@ class FieldDefinition
/** /**
* @param string $name * @param string $name
*
* @return FieldArgument|null * @return FieldArgument|null
*/ */
public function getArg($name) public function getArg($name)
@ -189,7 +191,7 @@ class FieldDefinition
} }
/** /**
* @return callable|\Closure * @return callable|callable
*/ */
public function getComplexityFn() public function getComplexityFn()
{ {

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Type\Definition; namespace GraphQL\Type\Definition;
use Exception;
use GraphQL\Error\Error; use GraphQL\Error\Error;
use GraphQL\Language\AST\FloatValueNode; use GraphQL\Language\AST\FloatValueNode;
use GraphQL\Language\AST\IntValueNode; use GraphQL\Language\AST\IntValueNode;
@ -27,7 +28,9 @@ values as specified by
/** /**
* @param mixed $value * @param mixed $value
*
* @return float|null * @return float|null
*
* @throws Error * @throws Error
*/ */
public function serialize($value) public function serialize($value)
@ -55,7 +58,9 @@ values as specified by
/** /**
* @param mixed $value * @param mixed $value
*
* @return float|null * @return float|null
*
* @throws Error * @throws Error
*/ */
public function parseValue($value) public function parseValue($value)
@ -66,8 +71,10 @@ values as specified by
/** /**
* @param Node $valueNode * @param Node $valueNode
* @param mixed[]|null $variables * @param mixed[]|null $variables
*
* @return float|null * @return float|null
* @throws \Exception *
* @throws Exception
*/ */
public function parseLiteral($valueNode, ?array $variables = null) public function parseLiteral($valueNode, ?array $variables = null)
{ {
@ -76,6 +83,6 @@ values as specified by
} }
// Intentionally without message, as all information already in wrapped Exception // Intentionally without message, as all information already in wrapped Exception
throw new \Exception(); throw new Exception();
} }
} }

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Type\Definition; namespace GraphQL\Type\Definition;
use Exception;
use GraphQL\Error\Error; use GraphQL\Error\Error;
use GraphQL\Language\AST\IntValueNode; use GraphQL\Language\AST\IntValueNode;
use GraphQL\Language\AST\Node; use GraphQL\Language\AST\Node;
@ -30,7 +31,9 @@ When expected as an input type, any string (such as `"4"`) or integer
/** /**
* @param mixed $value * @param mixed $value
*
* @return string * @return string
*
* @throws Error * @throws Error
*/ */
public function serialize($value) public function serialize($value)
@ -53,7 +56,9 @@ When expected as an input type, any string (such as `"4"`) or integer
/** /**
* @param mixed $value * @param mixed $value
*
* @return string * @return string
*
* @throws Error * @throws Error
*/ */
public function parseValue($value) public function parseValue($value)
@ -68,8 +73,10 @@ When expected as an input type, any string (such as `"4"`) or integer
/** /**
* @param Node $valueNode * @param Node $valueNode
* @param mixed[]|null $variables * @param mixed[]|null $variables
* @return null|string *
* @throws \Exception * @return string|null
*
* @throws Exception
*/ */
public function parseLiteral($valueNode, ?array $variables = null) public function parseLiteral($valueNode, ?array $variables = null)
{ {
@ -78,6 +85,6 @@ When expected as an input type, any string (such as `"4"`) or integer
} }
// Intentionally without message, as all information already in wrapped Exception // Intentionally without message, as all information already in wrapped Exception
throw new \Exception(); throw new Exception();
} }
} }

View File

@ -38,7 +38,6 @@ class InputObjectField
private $defaultValueExists = false; private $defaultValueExists = false;
/** /**
*
* @param mixed[] $opts * @param mixed[] $opts
*/ */
public function __construct(array $opts) public function __construct(array $opts)

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Type\Definition; namespace GraphQL\Type\Definition;
use Exception;
use GraphQL\Error\InvariantViolation; use GraphQL\Error\InvariantViolation;
use GraphQL\Language\AST\InputObjectTypeDefinitionNode; use GraphQL\Language\AST\InputObjectTypeDefinitionNode;
use GraphQL\Language\AST\InputObjectTypeExtensionNode; use GraphQL\Language\AST\InputObjectTypeExtensionNode;
@ -29,7 +30,6 @@ class InputObjectType extends Type implements InputType, NamedType
public $extensionASTNodes; public $extensionASTNodes;
/** /**
*
* @param mixed[] $config * @param mixed[] $config
*/ */
public function __construct(array $config) public function __construct(array $config)
@ -49,8 +49,10 @@ class InputObjectType extends Type implements InputType, NamedType
/** /**
* @param string $name * @param string $name
*
* @return InputObjectField * @return InputObjectField
* @throws \Exception *
* @throws Exception
*/ */
public function getField($name) public function getField($name)
{ {

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Type\Definition; namespace GraphQL\Type\Definition;
use Exception;
use GraphQL\Error\Error; use GraphQL\Error\Error;
use GraphQL\Language\AST\IntValueNode; use GraphQL\Language\AST\IntValueNode;
use GraphQL\Language\AST\Node; use GraphQL\Language\AST\Node;
@ -36,7 +37,9 @@ values. Int can represent values between -(2^31) and 2^31 - 1. ';
/** /**
* @param mixed $value * @param mixed $value
*
* @return int|null * @return int|null
*
* @throws Error * @throws Error
*/ */
public function serialize($value) public function serialize($value)
@ -46,6 +49,7 @@ values. Int can represent values between -(2^31) and 2^31 - 1. ';
/** /**
* @param mixed $value * @param mixed $value
*
* @return int * @return int
*/ */
private function coerceInt($value) private function coerceInt($value)
@ -78,7 +82,9 @@ values. Int can represent values between -(2^31) and 2^31 - 1. ';
/** /**
* @param mixed $value * @param mixed $value
*
* @return int|null * @return int|null
*
* @throws Error * @throws Error
*/ */
public function parseValue($value) public function parseValue($value)
@ -89,8 +95,10 @@ values. Int can represent values between -(2^31) and 2^31 - 1. ';
/** /**
* @param Node $valueNode * @param Node $valueNode
* @param mixed[]|null $variables * @param mixed[]|null $variables
*
* @return int|null * @return int|null
* @throws \Exception *
* @throws Exception
*/ */
public function parseLiteral($valueNode, ?array $variables = null) public function parseLiteral($valueNode, ?array $variables = null)
{ {
@ -102,6 +110,6 @@ values. Int can represent values between -(2^31) and 2^31 - 1. ';
} }
// Intentionally without message, as all information already in wrapped Exception // Intentionally without message, as all information already in wrapped Exception
throw new \Exception(); throw new Exception();
} }
} }

View File

@ -27,7 +27,6 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT
private $fields; private $fields;
/** /**
*
* @param mixed[] $config * @param mixed[] $config
*/ */
public function __construct(array $config) public function __construct(array $config)
@ -47,6 +46,7 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT
/** /**
* @param mixed $type * @param mixed $type
*
* @return self * @return self
*/ */
public static function assertInterfaceType($type) public static function assertInterfaceType($type)
@ -61,6 +61,7 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT
/** /**
* @param string $name * @param string $name
*
* @return FieldDefinition * @return FieldDefinition
*/ */
public function getField($name) public function getField($name)
@ -91,6 +92,7 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT
* *
* @param object $objectValue * @param object $objectValue
* @param mixed[] $context * @param mixed[] $context
*
* @return callable|null * @return callable|null
*/ */
public function resolveType($objectValue, $context, ResolveInfo $info) public function resolveType($objectValue, $context, ResolveInfo $info)

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Type\Definition; namespace GraphQL\Type\Definition;
use Exception;
use GraphQL\Error\Error; use GraphQL\Error\Error;
use GraphQL\Language\AST\Node; use GraphQL\Language\AST\Node;
@ -19,7 +20,9 @@ interface LeafType
* Serializes an internal value to include in a response. * Serializes an internal value to include in a response.
* *
* @param mixed $value * @param mixed $value
*
* @return mixed * @return mixed
*
* @throws Error * @throws Error
*/ */
public function serialize($value); public function serialize($value);
@ -30,7 +33,9 @@ interface LeafType
* In the case of an invalid value this method must throw an Exception * In the case of an invalid value this method must throw an Exception
* *
* @param mixed $value * @param mixed $value
*
* @return mixed * @return mixed
*
* @throws Error * @throws Error
*/ */
public function parseValue($value); public function parseValue($value);
@ -42,8 +47,10 @@ interface LeafType
* *
* @param Node $valueNode * @param Node $valueNode
* @param mixed[]|null $variables * @param mixed[]|null $variables
*
* @return mixed * @return mixed
* @throws \Exception *
* @throws Exception
*/ */
public function parseLiteral($valueNode, ?array $variables = null); public function parseLiteral($valueNode, ?array $variables = null);
} }

View File

@ -33,12 +33,13 @@ class ListOfType extends Type implements WrappingType, OutputType, InputType
/** /**
* @param bool $recurse * @param bool $recurse
*
* @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType * @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType
*/ */
public function getWrappedType($recurse = false) public function getWrappedType($recurse = false)
{ {
$type = $this->ofType; $type = $this->ofType;
return ($recurse && $type instanceof WrappingType) ? $type->getWrappedType($recurse) : $type; return $recurse && $type instanceof WrappingType ? $type->getWrappedType($recurse) : $type;
} }
} }

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Type\Definition; namespace GraphQL\Type\Definition;
use Exception;
use GraphQL\Error\InvariantViolation; use GraphQL\Error\InvariantViolation;
use GraphQL\Utils\Utils; use GraphQL\Utils\Utils;
@ -17,7 +18,8 @@ class NonNull extends Type implements WrappingType, OutputType, InputType
/** /**
* @param callable|Type $type * @param callable|Type $type
* @throws \Exception *
* @throws Exception
*/ */
public function __construct($type) public function __construct($type)
{ {
@ -26,6 +28,7 @@ class NonNull extends Type implements WrappingType, OutputType, InputType
/** /**
* @param mixed $type * @param mixed $type
*
* @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType * @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType
*/ */
public static function assertNullableType($type) public static function assertNullableType($type)
@ -40,6 +43,7 @@ class NonNull extends Type implements WrappingType, OutputType, InputType
/** /**
* @param mixed $type * @param mixed $type
*
* @return self * @return self
*/ */
public static function assertNullType($type) public static function assertNullType($type)
@ -62,13 +66,15 @@ class NonNull extends Type implements WrappingType, OutputType, InputType
/** /**
* @param bool $recurse * @param bool $recurse
*
* @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType * @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType
*
* @throws InvariantViolation * @throws InvariantViolation
*/ */
public function getWrappedType($recurse = false) public function getWrappedType($recurse = false)
{ {
$type = $this->ofType; $type = $this->ofType;
return ($recurse && $type instanceof WrappingType) ? $type->getWrappedType($recurse) : $type; return $recurse && $type instanceof WrappingType ? $type->getWrappedType($recurse) : $type;
} }
} }

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Type\Definition; namespace GraphQL\Type\Definition;
use Exception;
use GraphQL\Error\InvariantViolation; use GraphQL\Error\InvariantViolation;
use GraphQL\Language\AST\ObjectTypeDefinitionNode; use GraphQL\Language\AST\ObjectTypeDefinitionNode;
use GraphQL\Language\AST\ObjectTypeExtensionNode; use GraphQL\Language\AST\ObjectTypeExtensionNode;
@ -52,7 +53,6 @@ use function sprintf;
* ]; * ];
* } * }
* ]); * ]);
*
*/ */
class ObjectType extends Type implements OutputType, CompositeType, NamedType class ObjectType extends Type implements OutputType, CompositeType, NamedType
{ {
@ -75,7 +75,6 @@ class ObjectType extends Type implements OutputType, CompositeType, NamedType
private $interfaceMap; private $interfaceMap;
/** /**
*
* @param mixed[] $config * @param mixed[] $config
*/ */
public function __construct(array $config) public function __construct(array $config)
@ -96,6 +95,7 @@ class ObjectType extends Type implements OutputType, CompositeType, NamedType
/** /**
* @param mixed $type * @param mixed $type
*
* @return self * @return self
*/ */
public static function assertObjectType($type) public static function assertObjectType($type)
@ -110,8 +110,10 @@ class ObjectType extends Type implements OutputType, CompositeType, NamedType
/** /**
* @param string $name * @param string $name
*
* @return FieldDefinition * @return FieldDefinition
* @throws \Exception *
* @throws Exception
*/ */
public function getField($name) public function getField($name)
{ {
@ -125,6 +127,7 @@ class ObjectType extends Type implements OutputType, CompositeType, NamedType
/** /**
* @return FieldDefinition[] * @return FieldDefinition[]
*
* @throws InvariantViolation * @throws InvariantViolation
*/ */
public function getFields() public function getFields()
@ -139,6 +142,7 @@ class ObjectType extends Type implements OutputType, CompositeType, NamedType
/** /**
* @param InterfaceType $iface * @param InterfaceType $iface
*
* @return bool * @return bool
*/ */
public function implementsInterface($iface) public function implementsInterface($iface)
@ -184,6 +188,7 @@ class ObjectType extends Type implements OutputType, CompositeType, NamedType
/** /**
* @param mixed[] $value * @param mixed[] $value
* @param mixed[]|null $context * @param mixed[]|null $context
*
* @return bool|null * @return bool|null
*/ */
public function isTypeOf($value, $context, ResolveInfo $info) public function isTypeOf($value, $context, ResolveInfo $info)

View File

@ -139,9 +139,11 @@ class ResolveInfo
* Warning: this method it is a naive implementation which does not take into account * Warning: this method it is a naive implementation which does not take into account
* conditional typed fragments. So use it with care for fields of interface and union types. * conditional typed fragments. So use it with care for fields of interface and union types.
* *
* @api
* @param int $depth How many levels to include in output * @param int $depth How many levels to include in output
*
* @return bool[] * @return bool[]
*
* @api
*/ */
public function getFieldSelection($depth = 0) public function getFieldSelection($depth = 0)
{ {

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Type\Definition; namespace GraphQL\Type\Definition;
use Exception;
use GraphQL\Error\Error; use GraphQL\Error\Error;
use GraphQL\Language\AST\Node; use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\StringValueNode; use GraphQL\Language\AST\StringValueNode;
@ -29,7 +30,9 @@ represent free-form human-readable text.';
/** /**
* @param mixed $value * @param mixed $value
*
* @return mixed|string * @return mixed|string
*
* @throws Error * @throws Error
*/ */
public function serialize($value) public function serialize($value)
@ -67,7 +70,9 @@ represent free-form human-readable text.';
/** /**
* @param mixed $value * @param mixed $value
*
* @return string * @return string
*
* @throws Error * @throws Error
*/ */
public function parseValue($value) public function parseValue($value)
@ -78,8 +83,10 @@ represent free-form human-readable text.';
/** /**
* @param Node $valueNode * @param Node $valueNode
* @param mixed[]|null $variables * @param mixed[]|null $variables
* @return null|string *
* @throws \Exception * @return string|null
*
* @throws Exception
*/ */
public function parseLiteral($valueNode, ?array $variables = null) public function parseLiteral($valueNode, ?array $variables = null)
{ {
@ -88,6 +95,6 @@ represent free-form human-readable text.';
} }
// Intentionally without message, as all information already in wrapped Exception // Intentionally without message, as all information already in wrapped Exception
throw new \Exception(); throw new Exception();
} }
} }

View File

@ -4,10 +4,14 @@ declare(strict_types=1);
namespace GraphQL\Type\Definition; namespace GraphQL\Type\Definition;
use Exception;
use GraphQL\Error\InvariantViolation; use GraphQL\Error\InvariantViolation;
use GraphQL\Language\AST\TypeDefinitionNode; use GraphQL\Language\AST\TypeDefinitionNode;
use GraphQL\Type\Introspection; use GraphQL\Type\Introspection;
use GraphQL\Utils\Utils; use GraphQL\Utils\Utils;
use JsonSerializable;
use ReflectionClass;
use Throwable;
use function array_keys; use function array_keys;
use function array_merge; use function array_merge;
use function in_array; use function in_array;
@ -17,7 +21,7 @@ use function preg_replace;
* Registry of standard GraphQL types * Registry of standard GraphQL types
* and a base class for all other types. * and a base class for all other types.
*/ */
abstract class Type implements \JsonSerializable abstract class Type implements JsonSerializable
{ {
public const STRING = 'String'; public const STRING = 'String';
public const INT = 'Int'; public const INT = 'Int';
@ -44,8 +48,9 @@ abstract class Type implements \JsonSerializable
public $config; public $config;
/** /**
* @api
* @return IDType * @return IDType
*
* @api
*/ */
public static function id() public static function id()
{ {
@ -54,6 +59,7 @@ abstract class Type implements \JsonSerializable
/** /**
* @param string $name * @param string $name
*
* @return (IDType|StringType|FloatType|IntType|BooleanType)[]|IDType|StringType|FloatType|IntType|BooleanType * @return (IDType|StringType|FloatType|IntType|BooleanType)[]|IDType|StringType|FloatType|IntType|BooleanType
*/ */
private static function getInternalType($name = null) private static function getInternalType($name = null)
@ -72,8 +78,9 @@ abstract class Type implements \JsonSerializable
} }
/** /**
* @api
* @return StringType * @return StringType
*
* @api
*/ */
public static function string() public static function string()
{ {
@ -81,8 +88,9 @@ abstract class Type implements \JsonSerializable
} }
/** /**
* @api
* @return BooleanType * @return BooleanType
*
* @api
*/ */
public static function boolean() public static function boolean()
{ {
@ -90,8 +98,9 @@ abstract class Type implements \JsonSerializable
} }
/** /**
* @api
* @return IntType * @return IntType
*
* @api
*/ */
public static function int() public static function int()
{ {
@ -99,8 +108,9 @@ abstract class Type implements \JsonSerializable
} }
/** /**
* @api
* @return FloatType * @return FloatType
*
* @api
*/ */
public static function float() public static function float()
{ {
@ -108,9 +118,11 @@ abstract class Type implements \JsonSerializable
} }
/** /**
* @api
* @param Type|ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType|NonNull $wrappedType * @param Type|ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType|NonNull $wrappedType
*
* @return ListOfType * @return ListOfType
*
* @api
*/ */
public static function listOf($wrappedType) public static function listOf($wrappedType)
{ {
@ -118,9 +130,11 @@ abstract class Type implements \JsonSerializable
} }
/** /**
* @api
* @param ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType $wrappedType * @param ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType $wrappedType
*
* @return NonNull * @return NonNull
*
* @api
*/ */
public static function nonNull($wrappedType) public static function nonNull($wrappedType)
{ {
@ -166,9 +180,11 @@ abstract class Type implements \JsonSerializable
} }
/** /**
* @api
* @param Type $type * @param Type $type
*
* @return bool * @return bool
*
* @api
*/ */
public static function isInputType($type) public static function isInputType($type)
{ {
@ -180,9 +196,11 @@ abstract class Type implements \JsonSerializable
} }
/** /**
* @api
* @param Type $type * @param Type $type
*
* @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType * @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType
*
* @api
*/ */
public static function getNamedType($type) public static function getNamedType($type)
{ {
@ -197,9 +215,11 @@ abstract class Type implements \JsonSerializable
} }
/** /**
* @api
* @param Type $type * @param Type $type
*
* @return bool * @return bool
*
* @api
*/ */
public static function isOutputType($type) public static function isOutputType($type)
{ {
@ -211,9 +231,11 @@ abstract class Type implements \JsonSerializable
} }
/** /**
* @api
* @param Type $type * @param Type $type
*
* @return bool * @return bool
*
* @api
*/ */
public static function isLeafType($type) public static function isLeafType($type)
{ {
@ -221,9 +243,11 @@ abstract class Type implements \JsonSerializable
} }
/** /**
* @api
* @param Type $type * @param Type $type
*
* @return bool * @return bool
*
* @api
*/ */
public static function isCompositeType($type) public static function isCompositeType($type)
{ {
@ -231,9 +255,11 @@ abstract class Type implements \JsonSerializable
} }
/** /**
* @api
* @param Type $type * @param Type $type
*
* @return bool * @return bool
*
* @api
*/ */
public static function isAbstractType($type) public static function isAbstractType($type)
{ {
@ -242,6 +268,7 @@ abstract class Type implements \JsonSerializable
/** /**
* @param mixed $type * @param mixed $type
*
* @return mixed * @return mixed
*/ */
public static function assertType($type) public static function assertType($type)
@ -255,9 +282,11 @@ abstract class Type implements \JsonSerializable
} }
/** /**
* @api
* @param Type $type * @param Type $type
*
* @return bool * @return bool
*
* @api
*/ */
public static function isType($type) public static function isType($type)
{ {
@ -265,9 +294,11 @@ abstract class Type implements \JsonSerializable
} }
/** /**
* @api
* @param Type $type * @param Type $type
*
* @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType * @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType
*
* @api
*/ */
public static function getNullableType($type) public static function getNullableType($type)
{ {
@ -305,15 +336,15 @@ abstract class Type implements \JsonSerializable
{ {
try { try {
return $this->toString(); return $this->toString();
} catch (\Exception $e) { } catch (Exception $e) {
echo $e; echo $e;
} catch (\Throwable $e) { } catch (Throwable $e) {
echo $e; echo $e;
} }
} }
/** /**
* @return null|string * @return string|null
*/ */
protected function tryInferName() protected function tryInferName()
{ {
@ -324,7 +355,7 @@ abstract class Type implements \JsonSerializable
// If class is extended - infer name from className // If class is extended - infer name from className
// QueryType -> Type // QueryType -> Type
// SomeOtherType -> SomeOther // SomeOtherType -> SomeOther
$tmp = new \ReflectionClass($this); $tmp = new ReflectionClass($this);
$name = $tmp->getShortName(); $name = $tmp->getShortName();
if ($tmp->getNamespaceName() !== __NAMESPACE__) { if ($tmp->getNamespaceName() !== __NAMESPACE__) {

View File

@ -104,6 +104,7 @@ class UnionType extends Type implements AbstractType, OutputType, CompositeType,
* *
* @param object $objectValue * @param object $objectValue
* @param mixed $context * @param mixed $context
*
* @return callable|null * @return callable|null
*/ */
public function resolveType($objectValue, $context, ResolveInfo $info) public function resolveType($objectValue, $context, ResolveInfo $info)

View File

@ -8,6 +8,7 @@ interface WrappingType
{ {
/** /**
* @param bool $recurse * @param bool $recurse
*
* @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType * @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType
*/ */
public function getWrappedType($recurse = false); public function getWrappedType($recurse = false);

View File

@ -25,7 +25,6 @@ class EagerResolution implements Resolution
private $implementations = []; private $implementations = [];
/** /**
*
* @param Type[] $initialTypes * @param Type[] $initialTypes
*/ */
public function __construct(array $initialTypes) public function __construct(array $initialTypes)

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Type; namespace GraphQL\Type;
use Exception;
use GraphQL\Language\DirectiveLocation; use GraphQL\Language\DirectiveLocation;
use GraphQL\Language\Printer; use GraphQL\Language\Printer;
use GraphQL\Type\Definition\Directive; use GraphQL\Type\Definition\Directive;
@ -44,6 +45,7 @@ class Introspection
* Default: true * Default: true
* *
* @param bool[]|bool $options * @param bool[]|bool $options
*
* @return string * @return string
*/ */
public static function getIntrospectionQuery($options = []) public static function getIntrospectionQuery($options = [])
@ -157,6 +159,7 @@ EOD;
/** /**
* @param Type $type * @param Type $type
*
* @return bool * @return bool
*/ */
public static function isIntrospectionType($type) public static function isIntrospectionType($type)
@ -193,14 +196,14 @@ EOD;
'types' => [ 'types' => [
'description' => 'A list of all types supported by this server.', 'description' => 'A list of all types supported by this server.',
'type' => new NonNull(new ListOfType(new NonNull(self::_type()))), 'type' => new NonNull(new ListOfType(new NonNull(self::_type()))),
'resolve' => function (Schema $schema) { 'resolve' => static function (Schema $schema) {
return array_values($schema->getTypeMap()); return array_values($schema->getTypeMap());
}, },
], ],
'queryType' => [ 'queryType' => [
'description' => 'The type that query operations will be rooted at.', 'description' => 'The type that query operations will be rooted at.',
'type' => new NonNull(self::_type()), 'type' => new NonNull(self::_type()),
'resolve' => function (Schema $schema) { 'resolve' => static function (Schema $schema) {
return $schema->getQueryType(); return $schema->getQueryType();
}, },
], ],
@ -209,21 +212,21 @@ EOD;
'If this server supports mutation, the type that ' . 'If this server supports mutation, the type that ' .
'mutation operations will be rooted at.', 'mutation operations will be rooted at.',
'type' => self::_type(), 'type' => self::_type(),
'resolve' => function (Schema $schema) { 'resolve' => static function (Schema $schema) {
return $schema->getMutationType(); return $schema->getMutationType();
}, },
], ],
'subscriptionType' => [ 'subscriptionType' => [
'description' => 'If this server support subscription, the type that subscription operations will be rooted at.', 'description' => 'If this server support subscription, the type that subscription operations will be rooted at.',
'type' => self::_type(), 'type' => self::_type(),
'resolve' => function (Schema $schema) { 'resolve' => static function (Schema $schema) {
return $schema->getSubscriptionType(); return $schema->getSubscriptionType();
}, },
], ],
'directives' => [ 'directives' => [
'description' => 'A list of all directives supported by this server.', 'description' => 'A list of all directives supported by this server.',
'type' => Type::nonNull(Type::listOf(Type::nonNull(self::_directive()))), 'type' => Type::nonNull(Type::listOf(Type::nonNull(self::_directive()))),
'resolve' => function (Schema $schema) { 'resolve' => static function (Schema $schema) {
return $schema->getDirectives(); return $schema->getDirectives();
}, },
], ],
@ -250,11 +253,11 @@ EOD;
'Object and Interface types provide the fields they describe. Abstract ' . 'Object and Interface types provide the fields they describe. Abstract ' .
'types, Union and Interface, provide the Object types possible ' . 'types, Union and Interface, provide the Object types possible ' .
'at runtime. List and NonNull types compose other types.', 'at runtime. List and NonNull types compose other types.',
'fields' => function () { 'fields' => static function () {
return [ return [
'kind' => [ 'kind' => [
'type' => Type::nonNull(self::_typeKind()), 'type' => Type::nonNull(self::_typeKind()),
'resolve' => function (Type $type) { 'resolve' => static function (Type $type) {
switch (true) { switch (true) {
case $type instanceof ListOfType: case $type instanceof ListOfType:
return TypeKind::LIST_KIND; return TypeKind::LIST_KIND;
@ -273,7 +276,7 @@ EOD;
case $type instanceof UnionType: case $type instanceof UnionType:
return TypeKind::UNION; return TypeKind::UNION;
default: default:
throw new \Exception('Unknown kind of type: ' . Utils::printSafe($type)); throw new Exception('Unknown kind of type: ' . Utils::printSafe($type));
} }
}, },
], ],
@ -284,14 +287,14 @@ EOD;
'args' => [ 'args' => [
'includeDeprecated' => ['type' => Type::boolean(), 'defaultValue' => false], 'includeDeprecated' => ['type' => Type::boolean(), 'defaultValue' => false],
], ],
'resolve' => function (Type $type, $args) { 'resolve' => static function (Type $type, $args) {
if ($type instanceof ObjectType || $type instanceof InterfaceType) { if ($type instanceof ObjectType || $type instanceof InterfaceType) {
$fields = $type->getFields(); $fields = $type->getFields();
if (empty($args['includeDeprecated'])) { if (empty($args['includeDeprecated'])) {
$fields = array_filter( $fields = array_filter(
$fields, $fields,
function (FieldDefinition $field) { static function (FieldDefinition $field) {
return ! $field->deprecationReason; return ! $field->deprecationReason;
} }
); );
@ -305,7 +308,7 @@ EOD;
], ],
'interfaces' => [ 'interfaces' => [
'type' => Type::listOf(Type::nonNull(self::_type())), 'type' => Type::listOf(Type::nonNull(self::_type())),
'resolve' => function ($type) { 'resolve' => static function ($type) {
if ($type instanceof ObjectType) { if ($type instanceof ObjectType) {
return $type->getInterfaces(); return $type->getInterfaces();
} }
@ -315,7 +318,7 @@ EOD;
], ],
'possibleTypes' => [ 'possibleTypes' => [
'type' => Type::listOf(Type::nonNull(self::_type())), 'type' => Type::listOf(Type::nonNull(self::_type())),
'resolve' => function ($type, $args, $context, ResolveInfo $info) { 'resolve' => static function ($type, $args, $context, ResolveInfo $info) {
if ($type instanceof InterfaceType || $type instanceof UnionType) { if ($type instanceof InterfaceType || $type instanceof UnionType) {
return $info->schema->getPossibleTypes($type); return $info->schema->getPossibleTypes($type);
} }
@ -328,14 +331,14 @@ EOD;
'args' => [ 'args' => [
'includeDeprecated' => ['type' => Type::boolean(), 'defaultValue' => false], 'includeDeprecated' => ['type' => Type::boolean(), 'defaultValue' => false],
], ],
'resolve' => function ($type, $args) { 'resolve' => static function ($type, $args) {
if ($type instanceof EnumType) { if ($type instanceof EnumType) {
$values = array_values($type->getValues()); $values = array_values($type->getValues());
if (empty($args['includeDeprecated'])) { if (empty($args['includeDeprecated'])) {
$values = array_filter( $values = array_filter(
$values, $values,
function ($value) { static function ($value) {
return ! $value->deprecationReason; return ! $value->deprecationReason;
} }
); );
@ -349,7 +352,7 @@ EOD;
], ],
'inputFields' => [ 'inputFields' => [
'type' => Type::listOf(Type::nonNull(self::_inputValue())), 'type' => Type::listOf(Type::nonNull(self::_inputValue())),
'resolve' => function ($type) { 'resolve' => static function ($type) {
if ($type instanceof InputObjectType) { if ($type instanceof InputObjectType) {
return array_values($type->getFields()); return array_values($type->getFields());
} }
@ -359,7 +362,7 @@ EOD;
], ],
'ofType' => [ 'ofType' => [
'type' => self::_type(), 'type' => self::_type(),
'resolve' => function ($type) { 'resolve' => static function ($type) {
if ($type instanceof WrappingType) { if ($type instanceof WrappingType) {
return $type->getWrappedType(); return $type->getWrappedType();
} }
@ -431,25 +434,25 @@ EOD;
'description' => 'description' =>
'Object and Interface types are described by a list of Fields, each of ' . 'Object and Interface types are described by a list of Fields, each of ' .
'which has a name, potentially a list of arguments, and a return type.', 'which has a name, potentially a list of arguments, and a return type.',
'fields' => function () { 'fields' => static function () {
return [ return [
'name' => ['type' => Type::nonNull(Type::string())], 'name' => ['type' => Type::nonNull(Type::string())],
'description' => ['type' => Type::string()], 'description' => ['type' => Type::string()],
'args' => [ 'args' => [
'type' => Type::nonNull(Type::listOf(Type::nonNull(self::_inputValue()))), 'type' => Type::nonNull(Type::listOf(Type::nonNull(self::_inputValue()))),
'resolve' => function (FieldDefinition $field) { 'resolve' => static function (FieldDefinition $field) {
return empty($field->args) ? [] : $field->args; return empty($field->args) ? [] : $field->args;
}, },
], ],
'type' => [ 'type' => [
'type' => Type::nonNull(self::_type()), 'type' => Type::nonNull(self::_type()),
'resolve' => function (FieldDefinition $field) { 'resolve' => static function (FieldDefinition $field) {
return $field->getType(); return $field->getType();
}, },
], ],
'isDeprecated' => [ 'isDeprecated' => [
'type' => Type::nonNull(Type::boolean()), 'type' => Type::nonNull(Type::boolean()),
'resolve' => function (FieldDefinition $field) { 'resolve' => static function (FieldDefinition $field) {
return (bool) $field->deprecationReason; return (bool) $field->deprecationReason;
}, },
], ],
@ -474,13 +477,13 @@ EOD;
'Arguments provided to Fields or Directives and the input fields of an ' . 'Arguments provided to Fields or Directives and the input fields of an ' .
'InputObject are represented as Input Values which describe their type ' . 'InputObject are represented as Input Values which describe their type ' .
'and optionally a default value.', 'and optionally a default value.',
'fields' => function () { 'fields' => static function () {
return [ return [
'name' => ['type' => Type::nonNull(Type::string())], 'name' => ['type' => Type::nonNull(Type::string())],
'description' => ['type' => Type::string()], 'description' => ['type' => Type::string()],
'type' => [ 'type' => [
'type' => Type::nonNull(self::_type()), 'type' => Type::nonNull(self::_type()),
'resolve' => function ($value) { 'resolve' => static function ($value) {
return method_exists($value, 'getType') ? $value->getType() : $value->type; return method_exists($value, 'getType') ? $value->getType() : $value->type;
}, },
], ],
@ -488,7 +491,7 @@ EOD;
'type' => Type::string(), 'type' => Type::string(),
'description' => 'description' =>
'A GraphQL-formatted string representing the default value for this input value.', 'A GraphQL-formatted string representing the default value for this input value.',
'resolve' => function ($inputValue) { 'resolve' => static function ($inputValue) {
/** @var FieldArgument|InputObjectField $inputValue */ /** @var FieldArgument|InputObjectField $inputValue */
return ! $inputValue->defaultValueExists() return ! $inputValue->defaultValueExists()
? null ? null
@ -521,7 +524,7 @@ EOD;
'description' => ['type' => Type::string()], 'description' => ['type' => Type::string()],
'isDeprecated' => [ 'isDeprecated' => [
'type' => Type::nonNull(Type::boolean()), 'type' => Type::nonNull(Type::boolean()),
'resolve' => function ($enumValue) { 'resolve' => static function ($enumValue) {
return (bool) $enumValue->deprecationReason; return (bool) $enumValue->deprecationReason;
}, },
], ],
@ -557,7 +560,7 @@ EOD;
], ],
'args' => [ 'args' => [
'type' => Type::nonNull(Type::listOf(Type::nonNull(self::_inputValue()))), 'type' => Type::nonNull(Type::listOf(Type::nonNull(self::_inputValue()))),
'resolve' => function (Directive $directive) { 'resolve' => static function (Directive $directive) {
return $directive->args ?: []; return $directive->args ?: [];
}, },
], ],
@ -567,7 +570,7 @@ EOD;
'onOperation' => [ 'onOperation' => [
'deprecationReason' => 'Use `locations`.', 'deprecationReason' => 'Use `locations`.',
'type' => Type::nonNull(Type::boolean()), 'type' => Type::nonNull(Type::boolean()),
'resolve' => function ($d) { 'resolve' => static function ($d) {
return in_array(DirectiveLocation::QUERY, $d->locations) || return in_array(DirectiveLocation::QUERY, $d->locations) ||
in_array(DirectiveLocation::MUTATION, $d->locations) || in_array(DirectiveLocation::MUTATION, $d->locations) ||
in_array(DirectiveLocation::SUBSCRIPTION, $d->locations); in_array(DirectiveLocation::SUBSCRIPTION, $d->locations);
@ -576,7 +579,7 @@ EOD;
'onFragment' => [ 'onFragment' => [
'deprecationReason' => 'Use `locations`.', 'deprecationReason' => 'Use `locations`.',
'type' => Type::nonNull(Type::boolean()), 'type' => Type::nonNull(Type::boolean()),
'resolve' => function ($d) { 'resolve' => static function ($d) {
return in_array(DirectiveLocation::FRAGMENT_SPREAD, $d->locations) || return in_array(DirectiveLocation::FRAGMENT_SPREAD, $d->locations) ||
in_array(DirectiveLocation::INLINE_FRAGMENT, $d->locations) || in_array(DirectiveLocation::INLINE_FRAGMENT, $d->locations) ||
in_array(DirectiveLocation::FRAGMENT_DEFINITION, $d->locations); in_array(DirectiveLocation::FRAGMENT_DEFINITION, $d->locations);
@ -585,7 +588,7 @@ EOD;
'onField' => [ 'onField' => [
'deprecationReason' => 'Use `locations`.', 'deprecationReason' => 'Use `locations`.',
'type' => Type::nonNull(Type::boolean()), 'type' => Type::nonNull(Type::boolean()),
'resolve' => function ($d) { 'resolve' => static function ($d) {
return in_array(DirectiveLocation::FIELD, $d->locations); return in_array(DirectiveLocation::FIELD, $d->locations);
}, },
], ],
@ -694,7 +697,7 @@ EOD;
'type' => Type::nonNull(self::_schema()), 'type' => Type::nonNull(self::_schema()),
'description' => 'Access the current type schema of this server.', 'description' => 'Access the current type schema of this server.',
'args' => [], 'args' => [],
'resolve' => function ( 'resolve' => static function (
$source, $source,
$args, $args,
$context, $context,
@ -718,7 +721,7 @@ EOD;
'args' => [ 'args' => [
['name' => 'name', 'type' => Type::nonNull(Type::string())], ['name' => 'name', 'type' => Type::nonNull(Type::string())],
], ],
'resolve' => function ($source, $args, $context, ResolveInfo $info) { 'resolve' => static function ($source, $args, $context, ResolveInfo $info) {
return $info->schema->getType($args['name']); return $info->schema->getType($args['name']);
}, },
]); ]);
@ -735,7 +738,7 @@ EOD;
'type' => Type::nonNull(Type::string()), 'type' => Type::nonNull(Type::string()),
'description' => 'The name of the current Object type at runtime.', 'description' => 'The name of the current Object type at runtime.',
'args' => [], 'args' => [],
'resolve' => function ( 'resolve' => static function (
$source, $source,
$args, $args,
$context, $context,

View File

@ -42,7 +42,6 @@ class LazyResolution implements Resolution
private $loadedPossibleTypes; private $loadedPossibleTypes;
/** /**
*
* @param mixed[] $descriptor * @param mixed[] $descriptor
*/ */
public function __construct(array $descriptor, callable $typeLoader) public function __construct(array $descriptor, callable $typeLoader)

View File

@ -20,6 +20,7 @@ interface Resolution
* Returns instance of type with given $name for GraphQL Schema * Returns instance of type with given $name for GraphQL Schema
* *
* @param string $name * @param string $name
*
* @return Type * @return Type
*/ */
public function resolveType($name); public function resolveType($name);

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Type; namespace GraphQL\Type;
use Generator;
use GraphQL\Error\Error; use GraphQL\Error\Error;
use GraphQL\Error\InvariantViolation; use GraphQL\Error\InvariantViolation;
use GraphQL\GraphQL; use GraphQL\GraphQL;
@ -17,6 +18,7 @@ use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\UnionType; use GraphQL\Type\Definition\UnionType;
use GraphQL\Utils\TypeInfo; use GraphQL\Utils\TypeInfo;
use GraphQL\Utils\Utils; use GraphQL\Utils\Utils;
use Traversable;
use function array_values; use function array_values;
use function implode; use function implode;
use function is_array; use function is_array;
@ -72,8 +74,9 @@ class Schema
public $extensionASTNodes; public $extensionASTNodes;
/** /**
* @api
* @param mixed[]|SchemaConfig $config * @param mixed[]|SchemaConfig $config
*
* @api
*/ */
public function __construct($config) public function __construct($config)
{ {
@ -151,7 +154,7 @@ class Schema
} }
/** /**
* @return \Generator * @return Generator
*/ */
private function resolveAdditionalTypes() private function resolveAdditionalTypes()
{ {
@ -161,7 +164,7 @@ class Schema
$types = $types(); $types = $types();
} }
if (! is_array($types) && ! $types instanceof \Traversable) { if (! is_array($types) && ! $types instanceof Traversable) {
throw new InvariantViolation(sprintf( throw new InvariantViolation(sprintf(
'Schema types callable must return array or instance of Traversable but got: %s', 'Schema types callable must return array or instance of Traversable but got: %s',
Utils::getVariableType($types) Utils::getVariableType($types)
@ -186,8 +189,9 @@ class Schema
* *
* This operation requires full schema scan. Do not use in production environment. * This operation requires full schema scan. Do not use in production environment.
* *
* @api
* @return Type[] * @return Type[]
*
* @api
*/ */
public function getTypeMap() public function getTypeMap()
{ {
@ -228,8 +232,9 @@ class Schema
/** /**
* Returns a list of directives supported by this schema * Returns a list of directives supported by this schema
* *
* @api
* @return Directive[] * @return Directive[]
*
* @api
*/ */
public function getDirectives() public function getDirectives()
{ {
@ -239,8 +244,9 @@ class Schema
/** /**
* Returns schema query type * Returns schema query type
* *
* @api
* @return ObjectType * @return ObjectType
*
* @api
*/ */
public function getQueryType() public function getQueryType()
{ {
@ -250,8 +256,9 @@ class Schema
/** /**
* Returns schema mutation type * Returns schema mutation type
* *
* @api
* @return ObjectType|null * @return ObjectType|null
*
* @api
*/ */
public function getMutationType() public function getMutationType()
{ {
@ -261,8 +268,9 @@ class Schema
/** /**
* Returns schema subscription * Returns schema subscription
* *
* @api
* @return ObjectType|null * @return ObjectType|null
*
* @api
*/ */
public function getSubscriptionType() public function getSubscriptionType()
{ {
@ -270,8 +278,9 @@ class Schema
} }
/** /**
* @api
* @return SchemaConfig * @return SchemaConfig
*
* @api
*/ */
public function getConfig() public function getConfig()
{ {
@ -281,9 +290,11 @@ class Schema
/** /**
* Returns type by it's name * Returns type by it's name
* *
* @api
* @param string $name * @param string $name
*
* @return Type|null * @return Type|null
*
* @api
*/ */
public function getType($name) public function getType($name)
{ {
@ -300,6 +311,7 @@ class Schema
/** /**
* @param string $typeName * @param string $typeName
*
* @return Type * @return Type
*/ */
private function loadType($typeName) private function loadType($typeName)
@ -332,6 +344,7 @@ class Schema
/** /**
* @param string $typeName * @param string $typeName
*
* @return Type * @return Type
*/ */
private function defaultTypeLoader($typeName) private function defaultTypeLoader($typeName)
@ -348,8 +361,9 @@ class Schema
* *
* This operation requires full schema scan. Do not use in production environment. * This operation requires full schema scan. Do not use in production environment.
* *
* @api
* @return ObjectType[] * @return ObjectType[]
*
* @api
*/ */
public function getPossibleTypes(AbstractType $abstractType) public function getPossibleTypes(AbstractType $abstractType)
{ {
@ -389,8 +403,9 @@ class Schema
* Returns true if object type is concrete type of given abstract type * Returns true if object type is concrete type of given abstract type
* (implementation for interfaces and members of union type for unions) * (implementation for interfaces and members of union type for unions)
* *
* @api
* @return bool * @return bool
*
* @api
*/ */
public function isPossibleType(AbstractType $abstractType, ObjectType $possibleType) public function isPossibleType(AbstractType $abstractType, ObjectType $possibleType)
{ {
@ -405,9 +420,11 @@ class Schema
/** /**
* Returns instance of directive by name * Returns instance of directive by name
* *
* @api
* @param string $name * @param string $name
*
* @return Directive * @return Directive
*
* @api
*/ */
public function getDirective($name) public function getDirective($name)
{ {
@ -433,8 +450,9 @@ class Schema
* *
* This operation requires full schema scan. Do not use in production environment. * This operation requires full schema scan. Do not use in production environment.
* *
* @api
* @throws InvariantViolation * @throws InvariantViolation
*
* @api
*/ */
public function assertValid() public function assertValid()
{ {
@ -472,8 +490,9 @@ class Schema
* *
* This operation requires full schema scan. Do not use in production environment. * This operation requires full schema scan. Do not use in production environment.
* *
* @api
* @return InvariantViolation[]|Error[] * @return InvariantViolation[]|Error[]
*
* @api
*/ */
public function validate() public function validate()
{ {

View File

@ -24,7 +24,6 @@ use function is_callable;
* ->setTypeLoader($myTypeLoader); * ->setTypeLoader($myTypeLoader);
* *
* $schema = new Schema($config); * $schema = new Schema($config);
*
*/ */
class SchemaConfig class SchemaConfig
{ {
@ -59,9 +58,11 @@ class SchemaConfig
* Converts an array of options to instance of SchemaConfig * Converts an array of options to instance of SchemaConfig
* (or just returns empty config when array is not passed). * (or just returns empty config when array is not passed).
* *
* @api
* @param mixed[] $options * @param mixed[] $options
*
* @return SchemaConfig * @return SchemaConfig
*
* @api
*/ */
public static function create(array $options = []) public static function create(array $options = [])
{ {
@ -132,8 +133,9 @@ class SchemaConfig
} }
/** /**
* @api
* @return ObjectType * @return ObjectType
*
* @api
*/ */
public function getQuery() public function getQuery()
{ {
@ -141,9 +143,11 @@ class SchemaConfig
} }
/** /**
* @api
* @param ObjectType $query * @param ObjectType $query
*
* @return SchemaConfig * @return SchemaConfig
*
* @api
*/ */
public function setQuery($query) public function setQuery($query)
{ {
@ -153,8 +157,9 @@ class SchemaConfig
} }
/** /**
* @api
* @return ObjectType * @return ObjectType
*
* @api
*/ */
public function getMutation() public function getMutation()
{ {
@ -162,9 +167,11 @@ class SchemaConfig
} }
/** /**
* @api
* @param ObjectType $mutation * @param ObjectType $mutation
*
* @return SchemaConfig * @return SchemaConfig
*
* @api
*/ */
public function setMutation($mutation) public function setMutation($mutation)
{ {
@ -174,8 +181,9 @@ class SchemaConfig
} }
/** /**
* @api
* @return ObjectType * @return ObjectType
*
* @api
*/ */
public function getSubscription() public function getSubscription()
{ {
@ -183,9 +191,11 @@ class SchemaConfig
} }
/** /**
* @api
* @param ObjectType $subscription * @param ObjectType $subscription
*
* @return SchemaConfig * @return SchemaConfig
*
* @api
*/ */
public function setSubscription($subscription) public function setSubscription($subscription)
{ {
@ -195,8 +205,9 @@ class SchemaConfig
} }
/** /**
* @api
* @return Type[] * @return Type[]
*
* @api
*/ */
public function getTypes() public function getTypes()
{ {
@ -204,9 +215,11 @@ class SchemaConfig
} }
/** /**
* @api
* @param Type[]|callable $types * @param Type[]|callable $types
*
* @return SchemaConfig * @return SchemaConfig
*
* @api
*/ */
public function setTypes($types) public function setTypes($types)
{ {
@ -216,8 +229,9 @@ class SchemaConfig
} }
/** /**
* @api
* @return Directive[] * @return Directive[]
*
* @api
*/ */
public function getDirectives() public function getDirectives()
{ {
@ -225,9 +239,11 @@ class SchemaConfig
} }
/** /**
* @api
* @param Directive[] $directives * @param Directive[] $directives
*
* @return SchemaConfig * @return SchemaConfig
*
* @api
*/ */
public function setDirectives(array $directives) public function setDirectives(array $directives)
{ {
@ -237,8 +253,9 @@ class SchemaConfig
} }
/** /**
* @api
* @return callable * @return callable
*
* @api
*/ */
public function getTypeLoader() public function getTypeLoader()
{ {
@ -246,8 +263,9 @@ class SchemaConfig
} }
/** /**
* @api
* @return SchemaConfig * @return SchemaConfig
*
* @api
*/ */
public function setTypeLoader(callable $typeLoader) public function setTypeLoader(callable $typeLoader)
{ {
@ -266,6 +284,7 @@ class SchemaConfig
/** /**
* @param bool $assumeValid * @param bool $assumeValid
*
* @return SchemaConfig * @return SchemaConfig
*/ */
public function setAssumeValid($assumeValid) public function setAssumeValid($assumeValid)

View File

@ -207,6 +207,7 @@ class SchemaValidationContext
/** /**
* @param string $argName * @param string $argName
*
* @return InputValueDefinitionNode[] * @return InputValueDefinitionNode[]
*/ */
private function getAllDirectiveArgNodes(Directive $directive, $argName) private function getAllDirectiveArgNodes(Directive $directive, $argName)
@ -228,6 +229,7 @@ class SchemaValidationContext
/** /**
* @param string $argName * @param string $argName
*
* @return TypeNode|null * @return TypeNode|null
*/ */
private function getDirectiveArgTypeNode(Directive $directive, $argName) private function getDirectiveArgTypeNode(Directive $directive, $argName)
@ -358,6 +360,7 @@ class SchemaValidationContext
/** /**
* @param ObjectType|InterfaceType $type * @param ObjectType|InterfaceType $type
*
* @return ObjectTypeDefinitionNode[]|ObjectTypeExtensionNode[]|InterfaceTypeDefinitionNode[]|InterfaceTypeExtensionNode[] * @return ObjectTypeDefinitionNode[]|ObjectTypeExtensionNode[]|InterfaceTypeDefinitionNode[]|InterfaceTypeExtensionNode[]
*/ */
private function getAllObjectOrInterfaceNodes($type) private function getAllObjectOrInterfaceNodes($type)
@ -372,6 +375,7 @@ class SchemaValidationContext
/** /**
* @param ObjectType|InterfaceType $type * @param ObjectType|InterfaceType $type
* @param string $fieldName * @param string $fieldName
*
* @return FieldDefinitionNode[] * @return FieldDefinitionNode[]
*/ */
private function getAllFieldNodes($type, $fieldName) private function getAllFieldNodes($type, $fieldName)
@ -398,6 +402,7 @@ class SchemaValidationContext
/** /**
* @param ObjectType|InterfaceType $type * @param ObjectType|InterfaceType $type
* @param string $fieldName * @param string $fieldName
*
* @return TypeNode|null * @return TypeNode|null
*/ */
private function getFieldTypeNode($type, $fieldName) private function getFieldTypeNode($type, $fieldName)
@ -410,6 +415,7 @@ class SchemaValidationContext
/** /**
* @param ObjectType|InterfaceType $type * @param ObjectType|InterfaceType $type
* @param string $fieldName * @param string $fieldName
*
* @return FieldDefinitionNode|null * @return FieldDefinitionNode|null
*/ */
private function getFieldNode($type, $fieldName) private function getFieldNode($type, $fieldName)
@ -423,6 +429,7 @@ class SchemaValidationContext
* @param ObjectType|InterfaceType $type * @param ObjectType|InterfaceType $type
* @param string $fieldName * @param string $fieldName
* @param string $argName * @param string $argName
*
* @return InputValueDefinitionNode[] * @return InputValueDefinitionNode[]
*/ */
private function getAllFieldArgNodes($type, $fieldName, $argName) private function getAllFieldArgNodes($type, $fieldName, $argName)
@ -446,6 +453,7 @@ class SchemaValidationContext
* @param ObjectType|InterfaceType $type * @param ObjectType|InterfaceType $type
* @param string $fieldName * @param string $fieldName
* @param string $argName * @param string $argName
*
* @return TypeNode|null * @return TypeNode|null
*/ */
private function getFieldArgTypeNode($type, $fieldName, $argName) private function getFieldArgTypeNode($type, $fieldName, $argName)
@ -459,6 +467,7 @@ class SchemaValidationContext
* @param ObjectType|InterfaceType $type * @param ObjectType|InterfaceType $type
* @param string $fieldName * @param string $fieldName
* @param string $argName * @param string $argName
*
* @return InputValueDefinitionNode|null * @return InputValueDefinitionNode|null
*/ */
private function getFieldArgNode($type, $fieldName, $argName) private function getFieldArgNode($type, $fieldName, $argName)
@ -497,6 +506,7 @@ class SchemaValidationContext
/** /**
* @param InterfaceType $iface * @param InterfaceType $iface
*
* @return NamedTypeNode|null * @return NamedTypeNode|null
*/ */
private function getImplementsInterfaceNode(ObjectType $type, $iface) private function getImplementsInterfaceNode(ObjectType $type, $iface)
@ -508,6 +518,7 @@ class SchemaValidationContext
/** /**
* @param InterfaceType $iface * @param InterfaceType $iface
*
* @return NamedTypeNode[] * @return NamedTypeNode[]
*/ */
private function getAllImplementsInterfaceNodes(ObjectType $type, $iface) private function getAllImplementsInterfaceNodes(ObjectType $type, $iface)
@ -715,6 +726,7 @@ class SchemaValidationContext
/** /**
* @param string $typeName * @param string $typeName
*
* @return NamedTypeNode[] * @return NamedTypeNode[]
*/ */
private function getUnionMemberTypeNodes(UnionType $union, $typeName) private function getUnionMemberTypeNodes(UnionType $union, $typeName)
@ -722,7 +734,7 @@ class SchemaValidationContext
if ($union->astNode && $union->astNode->types) { if ($union->astNode && $union->astNode->types) {
return array_filter( return array_filter(
$union->astNode->types, $union->astNode->types,
function (NamedTypeNode $value) use ($typeName) { static function (NamedTypeNode $value) use ($typeName) {
return $value->name->value === $typeName; return $value->name->value === $typeName;
} }
); );
@ -770,6 +782,7 @@ class SchemaValidationContext
/** /**
* @param string $valueName * @param string $valueName
*
* @return EnumValueDefinitionNode[] * @return EnumValueDefinitionNode[]
*/ */
private function getEnumValueNodes(EnumType $enum, $valueName) private function getEnumValueNodes(EnumType $enum, $valueName)
@ -777,7 +790,7 @@ class SchemaValidationContext
if ($enum->astNode && $enum->astNode->values) { if ($enum->astNode && $enum->astNode->values) {
return array_filter( return array_filter(
iterator_to_array($enum->astNode->values), iterator_to_array($enum->astNode->values),
function (EnumValueDefinitionNode $value) use ($valueName) { static function (EnumValueDefinitionNode $value) use ($valueName) {
return $value->name->value === $valueName; return $value->name->value === $valueName;
} }
); );