From b68e96b88f8b8745d79b68f900623ae43bf925b9 Mon Sep 17 00:00:00 2001 From: bladl <32598874+bladl@users.noreply.github.com> Date: Sat, 29 Oct 2022 01:23:45 +0300 Subject: [PATCH] Normalize types of RootTypeMapperInterface (#520) * psr/container v2 * Implement replacement for Picotainer * Replace Picotainer with LazyContainer in tests and documentation for version >=6 * Fix tests for phpdocumentor/type-resolver minor update * run cs-fix script * Fix some cs-fixer errors manually * fix return type * abandon psr/container ^1 * Test for LazyContainer * Normalize RootTypeMapperInterface --- src/Mappers/Root/BaseTypeMapper.php | 2 +- src/Mappers/Root/CompoundTypeMapper.php | 2 +- src/Mappers/Root/EnumTypeMapper.php | 4 ++-- src/Mappers/Root/FinalRootTypeMapper.php | 2 +- src/Mappers/Root/IteratorTypeMapper.php | 2 +- src/Mappers/Root/MyCLabsEnumTypeMapper.php | 3 +-- src/Mappers/Root/NullableTypeMapperAdapter.php | 2 +- src/Mappers/Root/RootTypeMapperInterface.php | 2 +- tests/Mappers/Root/NullableTypeMapperAdapterTest.php | 2 +- tests/Mappers/Root/VoidRootTypeMapper.php | 12 ++++-------- 10 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/Mappers/Root/BaseTypeMapper.php b/src/Mappers/Root/BaseTypeMapper.php index 19e8b03d3d..22ec7a8ff6 100644 --- a/src/Mappers/Root/BaseTypeMapper.php +++ b/src/Mappers/Root/BaseTypeMapper.php @@ -78,7 +78,7 @@ public function toGraphQLOutputType(Type $type, OutputType|null $subType, Reflec * @throws CannotMapTypeException * @throws CannotMapTypeExceptionInterface */ - public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + public function toGraphQLInputType(Type $type, InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType { $mappedType = $this->mapBaseType($type); if ($mappedType !== null) { diff --git a/src/Mappers/Root/CompoundTypeMapper.php b/src/Mappers/Root/CompoundTypeMapper.php index 2780769356..ed9f995873 100644 --- a/src/Mappers/Root/CompoundTypeMapper.php +++ b/src/Mappers/Root/CompoundTypeMapper.php @@ -81,7 +81,7 @@ public function toGraphQLOutputType(Type $type, OutputType|null $subType, Reflec return $return; } - public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + public function toGraphQLInputType(Type $type, InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType { if (! $type instanceof Compound) { return $this->next->toGraphQLInputType($type, $subType, $argumentName, $reflector, $docBlockObj); diff --git a/src/Mappers/Root/EnumTypeMapper.php b/src/Mappers/Root/EnumTypeMapper.php index 434f901430..fbe6e6802f 100644 --- a/src/Mappers/Root/EnumTypeMapper.php +++ b/src/Mappers/Root/EnumTypeMapper.php @@ -65,11 +65,11 @@ public function toGraphQLOutputType( */ public function toGraphQLInputType( Type $type, - InputType|GraphQLType|null $subType, + InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj, - ): InputType|GraphQLType + ): InputType { $result = $this->map($type); if ($result === null) { diff --git a/src/Mappers/Root/FinalRootTypeMapper.php b/src/Mappers/Root/FinalRootTypeMapper.php index a9cceb5c99..e7881c5843 100644 --- a/src/Mappers/Root/FinalRootTypeMapper.php +++ b/src/Mappers/Root/FinalRootTypeMapper.php @@ -40,7 +40,7 @@ public function toGraphQLOutputType(Type $type, OutputType|null $subType, Reflec } /** @throws CannotMapTypeException */ - public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + public function toGraphQLInputType(Type $type, InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType { throw CannotMapTypeException::createForPhpDocType($type); } diff --git a/src/Mappers/Root/IteratorTypeMapper.php b/src/Mappers/Root/IteratorTypeMapper.php index c77ecba902..f0eaca1ab7 100644 --- a/src/Mappers/Root/IteratorTypeMapper.php +++ b/src/Mappers/Root/IteratorTypeMapper.php @@ -70,7 +70,7 @@ public function toGraphQLOutputType(Type $type, OutputType|null $subType, Reflec return $result; } - public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + public function toGraphQLInputType(Type $type, InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType { if (! $type instanceof Compound) { //try { diff --git a/src/Mappers/Root/MyCLabsEnumTypeMapper.php b/src/Mappers/Root/MyCLabsEnumTypeMapper.php index 5d9630c278..1797e27720 100644 --- a/src/Mappers/Root/MyCLabsEnumTypeMapper.php +++ b/src/Mappers/Root/MyCLabsEnumTypeMapper.php @@ -8,7 +8,6 @@ use GraphQL\Type\Definition\InputType; use GraphQL\Type\Definition\NamedType; use GraphQL\Type\Definition\OutputType; -use GraphQL\Type\Definition\Type as GraphQLType; use MyCLabs\Enum\Enum; use phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\Type; @@ -46,7 +45,7 @@ public function toGraphQLOutputType(Type $type, OutputType|null $subType, Reflec return $result ?? $this->next->toGraphQLOutputType($type, $subType, $reflector, $docBlockObj); } - public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + public function toGraphQLInputType(Type $type, InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType { $result = $this->map($type); return $result ?? $this->next->toGraphQLInputType($type, $subType, $argumentName, $reflector, $docBlockObj); diff --git a/src/Mappers/Root/NullableTypeMapperAdapter.php b/src/Mappers/Root/NullableTypeMapperAdapter.php index 06f11beef0..09260e0d16 100644 --- a/src/Mappers/Root/NullableTypeMapperAdapter.php +++ b/src/Mappers/Root/NullableTypeMapperAdapter.php @@ -65,7 +65,7 @@ public function toGraphQLOutputType(Type $type, OutputType|GraphQLType|null $sub return $graphQlType; } - public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + public function toGraphQLInputType(Type $type, InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType { // Let's check a "null" value in the docblock $isNullable = $this->isNullable($type); diff --git a/src/Mappers/Root/RootTypeMapperInterface.php b/src/Mappers/Root/RootTypeMapperInterface.php index 1a9faa16cc..03fc11aa11 100644 --- a/src/Mappers/Root/RootTypeMapperInterface.php +++ b/src/Mappers/Root/RootTypeMapperInterface.php @@ -37,7 +37,7 @@ public function toGraphQLOutputType(Type $type, OutputType|null $subType, Reflec * * @return InputType&GraphQLType */ - public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType; + public function toGraphQLInputType(Type $type, InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType; /** * Returns a GraphQL type by name. diff --git a/tests/Mappers/Root/NullableTypeMapperAdapterTest.php b/tests/Mappers/Root/NullableTypeMapperAdapterTest.php index c8a52f1ee4..447d12f503 100644 --- a/tests/Mappers/Root/NullableTypeMapperAdapterTest.php +++ b/tests/Mappers/Root/NullableTypeMapperAdapterTest.php @@ -55,7 +55,7 @@ public function toGraphQLOutputType(Type $type, ?OutputType $subType, $reflector return new NonNull(new StringType()); } - public function toGraphQLInputType(Type $type, null|InputType|GraphQLType $subType, string $argumentName, $reflector, DocBlock $docBlockObj): InputType + public function toGraphQLInputType(Type $type, null|InputType $subType, string $argumentName, $reflector, DocBlock $docBlockObj): InputType { throw new \RuntimeException('Not implemented'); } diff --git a/tests/Mappers/Root/VoidRootTypeMapper.php b/tests/Mappers/Root/VoidRootTypeMapper.php index 168140724f..42b0c17906 100644 --- a/tests/Mappers/Root/VoidRootTypeMapper.php +++ b/tests/Mappers/Root/VoidRootTypeMapper.php @@ -1,9 +1,9 @@ next->toGraphQLOutputType($type, $subType, $reflector, $docBlockObj); } /** * @param (InputType&GraphQLType)|null $subType - * @param ReflectionMethod|ReflectionProperty $reflector * * @return InputType&GraphQLType */ - public function toGraphQLInputType(Type $type, null|InputType|GraphQLType $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + public function toGraphQLInputType(Type $type, InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType { return $this->next->toGraphQLInputType($type, $subType, $argumentName, $reflector, $docBlockObj); }