From 760f8205550974ab45dae153eff58f8061cc9ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Tue, 5 Nov 2019 14:18:29 +0100 Subject: [PATCH] Fixing union type exception message when types are not "named" --- src/Mappers/CannotMapTypeException.php | 16 ++++++++-------- tests/Mappers/Parameters/TypeMapperTest.php | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Mappers/CannotMapTypeException.php b/src/Mappers/CannotMapTypeException.php index 67a0f84bcc..bcb043d2ce 100644 --- a/src/Mappers/CannotMapTypeException.php +++ b/src/Mappers/CannotMapTypeException.php @@ -47,14 +47,14 @@ public static function createForParseError(Error $error): self */ public static function createForBadTypeInUnion(array $unionTypes): self { - $disallowedTypes = array_filter($unionTypes, static function (Type $type) { - return $type instanceof NamedType; - }); - $disallowedTypeNames = array_map(static function (NamedType $type) { - return $type->name; - }, $disallowedTypes); - - return new self('In GraphQL, you can only use union types between objects. These types cannot be used in union types: ' . implode(', ', $disallowedTypeNames)); + $disallowedTypeNames = array_map(static function (Type $type) { + if ($type instanceof NamedType) { + return $type->name; + } + return (string) $type; + }, $unionTypes); + + return new self('in GraphQL, you can only use union types between objects. These types cannot be used in union types: ' . implode(', ', $disallowedTypeNames)); } public static function mustBeOutputType(string $subTypeName): self diff --git a/tests/Mappers/Parameters/TypeMapperTest.php b/tests/Mappers/Parameters/TypeMapperTest.php index 4ec2068cee..e558fa2561 100644 --- a/tests/Mappers/Parameters/TypeMapperTest.php +++ b/tests/Mappers/Parameters/TypeMapperTest.php @@ -30,7 +30,7 @@ public function testMapScalarUnionException(): void $docBlockObj = $cachedDocBlockFactory->getDocBlock($refMethod); $this->expectException(CannotMapTypeException::class); - $this->expectExceptionMessage('In GraphQL, you can only use union types between objects. These types cannot be used in union types: Int, String'); + $this->expectExceptionMessage('in GraphQL, you can only use union types between objects. These types cannot be used in union types: Int, String'); $typeMapper->mapReturnType($refMethod, $docBlockObj); }