Skip to content

Commit

Permalink
Normalize types of RootTypeMapperInterface (#520)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
l-you authored Oct 28, 2022
1 parent fed9ffe commit b68e96b
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Mappers/Root/BaseTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Mappers/Root/CompoundTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Mappers/Root/EnumTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Mappers/Root/FinalRootTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mappers/Root/IteratorTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/Mappers/Root/MyCLabsEnumTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Mappers/Root/NullableTypeMapperAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Mappers/Root/RootTypeMapperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/Mappers/Root/NullableTypeMapperAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
12 changes: 4 additions & 8 deletions tests/Mappers/Root/VoidRootTypeMapper.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

declare(strict_types=1);

namespace TheCodingMachine\GraphQLite\Mappers\Root;


use GraphQL\Type\Definition\InputType;
use GraphQL\Type\Definition\NamedType;
use GraphQL\Type\Definition\OutputType;
Expand All @@ -15,9 +15,7 @@

class VoidRootTypeMapper implements RootTypeMapperInterface
{
/**
* @var RootTypeMapperInterface
*/
/** @var RootTypeMapperInterface */
private $next;

public function __construct(RootTypeMapperInterface $next)
Expand All @@ -27,22 +25,20 @@ public function __construct(RootTypeMapperInterface $next)

/**
* @param (OutputType&GraphQLType)|null $subType
* @param ReflectionMethod|ReflectionProperty $reflector
*
* @return OutputType&GraphQLType
*/
public function toGraphQLOutputType(Type $type, ?OutputType $subType, $reflector, DocBlock $docBlockObj): OutputType
public function toGraphQLOutputType(Type $type, OutputType|null $subType, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): OutputType
{
return $this->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);
}
Expand Down

0 comments on commit b68e96b

Please sign in to comment.