Skip to content

Commit

Permalink
Fix named types resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg-web committed Dec 22, 2021
1 parent 7dcee7f commit 2c02009
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Resolver/TypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function resolve($alias): ?Type
if (!isset($this->cache[$alias])) {
$type = $this->baseType($alias);
$this->cache[$alias] = $type;
if (isset($type->name) && $type->name !== $alias) {
$this->cache[$type->name] = $type;
}
}

return $this->cache[$alias];
Expand Down
7 changes: 5 additions & 2 deletions tests/Functional/MultipleSchema/MultipleSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Overblog\GraphQLBundle\Tests\Functional\MultipleSchema;

use Overblog\GraphQLBundle\Resolver\UnresolvableException;
use Overblog\GraphQLBundle\Tests\Functional\TestCase;

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

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

private function assertSchemaQueryTypeName(string $typeName): void
Expand Down

0 comments on commit 2c02009

Please sign in to comment.