|
2 | 2 |
|
3 | 3 | namespace TheCodingMachine\GraphQLite\Mappers\Root; |
4 | 4 |
|
| 5 | +use GraphQL\Type\Definition\InputType; |
| 6 | +use GraphQL\Type\Definition\NamedType; |
5 | 7 | use GraphQL\Type\Definition\NonNull; |
| 8 | +use GraphQL\Type\Definition\OutputType; |
| 9 | +use GraphQL\Type\Definition\StringType; |
| 10 | +use GraphQL\Type\Definition\Type as GraphQLType; |
6 | 11 | use phpDocumentor\Reflection\DocBlock; |
| 12 | +use phpDocumentor\Reflection\Type; |
7 | 13 | use ReflectionMethod; |
8 | 14 | use TheCodingMachine\GraphQLite\AbstractQueryProviderTest; |
9 | 15 | use TheCodingMachine\GraphQLite\Fixtures\TestObject; |
@@ -37,4 +43,32 @@ public function testOnlyNull2(): void |
37 | 43 | $this->expectExceptionMessage('type-hinting against null only in the PHPDoc is not allowed.'); |
38 | 44 | $compoundTypeMapper->toGraphQLInputType($this->resolveType('null'), null, 'foo', new ReflectionMethod(__CLASS__, 'testMultipleCompound'), new DocBlock()); |
39 | 45 | } |
| 46 | + |
| 47 | + public function testNonNullableReturnedByWrappedMapper(): void |
| 48 | + { |
| 49 | + $typeMapper = new NullableTypeMapperAdapter(); |
| 50 | + |
| 51 | + $typeMapper->setNext(new class implements RootTypeMapperInterface { |
| 52 | + |
| 53 | + public function toGraphQLOutputType(Type $type, ?OutputType $subType, ReflectionMethod $refMethod, DocBlock $docBlockObj): OutputType |
| 54 | + { |
| 55 | + return new NonNull(new StringType()); |
| 56 | + } |
| 57 | + |
| 58 | + public function toGraphQLInputType(Type $type, ?InputType $subType, string $argumentName, ReflectionMethod $refMethod, DocBlock $docBlockObj): InputType |
| 59 | + { |
| 60 | + throw new \RuntimeException('Not implemented'); |
| 61 | + } |
| 62 | + |
| 63 | + public function mapNameToType(string $typeName): NamedType |
| 64 | + { |
| 65 | + throw new \RuntimeException('Not implemented'); |
| 66 | + } |
| 67 | + }); |
| 68 | + |
| 69 | + |
| 70 | + $this->expectException(CannotMapTypeException::class); |
| 71 | + $this->expectExceptionMessage('a type mapper returned a GraphQL\\Type\\Definition\\NonNull instance.'); |
| 72 | + $typeMapper->toGraphQLOutputType($this->resolveType(TestObject::class.'|'.TestObject2::class.'|null'), null, new ReflectionMethod(__CLASS__, 'testMultipleCompound'), new DocBlock()); |
| 73 | + } |
40 | 74 | } |
0 commit comments