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 mixed[] $context
*
* @return mixed
*/
public function resolveType($objectValue, $context, ResolveInfo $info);

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Type\Definition;
use Exception;
use GraphQL\Error\Error;
use GraphQL\Language\AST\BooleanValueNode;
use GraphQL\Language\AST\Node;
@ -23,6 +24,7 @@ class BooleanType extends ScalarType
/**
* @param mixed $value
*
* @return bool
*/
public function serialize($value)
@ -32,7 +34,9 @@ class BooleanType extends ScalarType
/**
* @param mixed $value
*
* @return bool
*
* @throws Error
*/
public function parseValue($value)
@ -47,8 +51,10 @@ class BooleanType extends ScalarType
/**
* @param Node $valueNode
* @param mixed[]|null $variables
*
* @return bool|null
* @throws \Exception
*
* @throws Exception
*/
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
throw new \Exception();
throw new Exception();
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Type\Definition;
use Exception;
use GraphQL\Error\Error;
use GraphQL\Language\AST\FloatValueNode;
use GraphQL\Language\AST\IntValueNode;
@ -27,7 +28,9 @@ values as specified by
/**
* @param mixed $value
*
* @return float|null
*
* @throws Error
*/
public function serialize($value)
@ -55,7 +58,9 @@ values as specified by
/**
* @param mixed $value
*
* @return float|null
*
* @throws Error
*/
public function parseValue($value)
@ -66,8 +71,10 @@ values as specified by
/**
* @param Node $valueNode
* @param mixed[]|null $variables
*
* @return float|null
* @throws \Exception
*
* @throws Exception
*/
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
throw new \Exception();
throw new Exception();
}
}

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Type\Definition;
use Exception;
use GraphQL\Error\Error;
use GraphQL\Language\AST\IntValueNode;
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
*
* @return string
*
* @throws Error
*/
public function serialize($value)
@ -53,7 +56,9 @@ When expected as an input type, any string (such as `"4"`) or integer
/**
* @param mixed $value
*
* @return string
*
* @throws Error
*/
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 mixed[]|null $variables
* @return null|string
* @throws \Exception
*
* @return string|null
*
* @throws Exception
*/
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
throw new \Exception();
throw new Exception();
}
}

View File

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

View File

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

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Type\Definition;
use Exception;
use GraphQL\Error\Error;
use GraphQL\Language\AST\IntValueNode;
use GraphQL\Language\AST\Node;
@ -36,7 +37,9 @@ values. Int can represent values between -(2^31) and 2^31 - 1. ';
/**
* @param mixed $value
*
* @return int|null
*
* @throws Error
*/
public function serialize($value)
@ -46,6 +49,7 @@ values. Int can represent values between -(2^31) and 2^31 - 1. ';
/**
* @param mixed $value
*
* @return int
*/
private function coerceInt($value)
@ -78,7 +82,9 @@ values. Int can represent values between -(2^31) and 2^31 - 1. ';
/**
* @param mixed $value
*
* @return int|null
*
* @throws Error
*/
public function parseValue($value)
@ -89,8 +95,10 @@ values. Int can represent values between -(2^31) and 2^31 - 1. ';
/**
* @param Node $valueNode
* @param mixed[]|null $variables
*
* @return int|null
* @throws \Exception
*
* @throws Exception
*/
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
throw new \Exception();
throw new Exception();
}
}

View File

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

View File

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

View File

@ -33,12 +33,13 @@ class ListOfType extends Type implements WrappingType, OutputType, InputType
/**
* @param bool $recurse
*
* @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType
*/
public function getWrappedType($recurse = false)
{
$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;
use Exception;
use GraphQL\Error\InvariantViolation;
use GraphQL\Utils\Utils;
@ -17,7 +18,8 @@ class NonNull extends Type implements WrappingType, OutputType, InputType
/**
* @param callable|Type $type
* @throws \Exception
*
* @throws Exception
*/
public function __construct($type)
{
@ -26,6 +28,7 @@ class NonNull extends Type implements WrappingType, OutputType, InputType
/**
* @param mixed $type
*
* @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType
*/
public static function assertNullableType($type)
@ -40,6 +43,7 @@ class NonNull extends Type implements WrappingType, OutputType, InputType
/**
* @param mixed $type
*
* @return self
*/
public static function assertNullType($type)
@ -62,13 +66,15 @@ class NonNull extends Type implements WrappingType, OutputType, InputType
/**
* @param bool $recurse
*
* @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType
*
* @throws InvariantViolation
*/
public function getWrappedType($recurse = false)
{
$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;
use Exception;
use GraphQL\Error\InvariantViolation;
use GraphQL\Language\AST\ObjectTypeDefinitionNode;
use GraphQL\Language\AST\ObjectTypeExtensionNode;
@ -52,7 +53,6 @@ use function sprintf;
* ];
* }
* ]);
*
*/
class ObjectType extends Type implements OutputType, CompositeType, NamedType
{
@ -75,7 +75,6 @@ class ObjectType extends Type implements OutputType, CompositeType, NamedType
private $interfaceMap;
/**
*
* @param mixed[] $config
*/
public function __construct(array $config)
@ -96,6 +95,7 @@ class ObjectType extends Type implements OutputType, CompositeType, NamedType
/**
* @param mixed $type
*
* @return self
*/
public static function assertObjectType($type)
@ -110,8 +110,10 @@ class ObjectType extends Type implements OutputType, CompositeType, NamedType
/**
* @param string $name
*
* @return FieldDefinition
* @throws \Exception
*
* @throws Exception
*/
public function getField($name)
{
@ -125,6 +127,7 @@ class ObjectType extends Type implements OutputType, CompositeType, NamedType
/**
* @return FieldDefinition[]
*
* @throws InvariantViolation
*/
public function getFields()
@ -139,6 +142,7 @@ class ObjectType extends Type implements OutputType, CompositeType, NamedType
/**
* @param InterfaceType $iface
*
* @return bool
*/
public function implementsInterface($iface)
@ -184,6 +188,7 @@ class ObjectType extends Type implements OutputType, CompositeType, NamedType
/**
* @param mixed[] $value
* @param mixed[]|null $context
*
* @return bool|null
*/
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
* 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
*
* @return bool[]
*
* @api
*/
public function getFieldSelection($depth = 0)
{

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Type\Definition;
use Exception;
use GraphQL\Error\Error;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\StringValueNode;
@ -29,7 +30,9 @@ represent free-form human-readable text.';
/**
* @param mixed $value
*
* @return mixed|string
*
* @throws Error
*/
public function serialize($value)
@ -67,7 +70,9 @@ represent free-form human-readable text.';
/**
* @param mixed $value
*
* @return string
*
* @throws Error
*/
public function parseValue($value)
@ -78,8 +83,10 @@ represent free-form human-readable text.';
/**
* @param Node $valueNode
* @param mixed[]|null $variables
* @return null|string
* @throws \Exception
*
* @return string|null
*
* @throws Exception
*/
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
throw new \Exception();
throw new Exception();
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -42,7 +42,6 @@ class LazyResolution implements Resolution
private $loadedPossibleTypes;
/**
*
* @param mixed[] $descriptor
*/
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
*
* @param string $name
*
* @return Type
*/
public function resolveType($name);

View File

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

View File

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

View File

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