Skip to content

Commit 2c02009

Browse files
author
Jeremiah VALERIE
committed
Fix named types resolving
1 parent 7dcee7f commit 2c02009

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Resolver/TypeResolver.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public function resolve($alias): ?Type
5151
if (!isset($this->cache[$alias])) {
5252
$type = $this->baseType($alias);
5353
$this->cache[$alias] = $type;
54+
if (isset($type->name) && $type->name !== $alias) {
55+
$this->cache[$type->name] = $type;
56+
}
5457
}
5558

5659
return $this->cache[$alias];

tests/Functional/MultipleSchema/MultipleSchemaTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Overblog\GraphQLBundle\Tests\Functional\MultipleSchema;
66

7+
use Overblog\GraphQLBundle\Resolver\UnresolvableException;
78
use Overblog\GraphQLBundle\Tests\Functional\TestCase;
89

910
final class MultipleSchemaTest extends TestCase
@@ -73,11 +74,13 @@ public function testInternalSchema(): void
7374
$this->assertGraphQL($query, $expectedData, null, [], 'internal');
7475
}
7576

76-
public function testUnknownTypeShouldReturnNull(): void
77+
public function testUnknownTypeShouldThrowAnUnresolvableException(): void
7778
{
7879
// @phpstan-ignore-next-line
7980
$schema = $this->getContainer()->get('overblog_graphql.request_executor')->getSchema('public');
80-
$this->assertNull($schema->getType('unknown'));
81+
$this->expectException(UnresolvableException::class);
82+
$this->expectExceptionMessage('Could not find type with alias "unknown". Did you forget to define it?');
83+
$schema->getType('unknown');
8184
}
8285

8386
private function assertSchemaQueryTypeName(string $typeName): void

0 commit comments

Comments
 (0)