Skip to content

Commit ebdcfe0

Browse files
authored
Merge pull request #888 from ruudk/remove-addDefaultFallBackToTypeLoader
Remove `addDefaultFallBackToTypeLoader`
2 parents 18a0fa0 + 2c02009 commit ebdcfe0

File tree

3 files changed

+10
-30
lines changed

3 files changed

+10
-30
lines changed

src/Definition/Type/ExtensibleSchema.php

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44

55
namespace Overblog\GraphQLBundle\Definition\Type;
66

7-
use GraphQL\Type\Definition\Type;
87
use GraphQL\Type\Schema;
98
use GraphQL\Type\SchemaConfig;
109
use Overblog\GraphQLBundle\Definition\Type\SchemaExtension\SchemaExtensionInterface;
11-
use Overblog\GraphQLBundle\Resolver\UnresolvableException;
1210

1311
class ExtensibleSchema extends Schema
1412
{
1513
public function __construct($config)
1614
{
17-
parent::__construct($this->addDefaultFallBackToTypeLoader(
15+
parent::__construct(
1816
$config instanceof SchemaConfig ? $config : SchemaConfig::create($config)
19-
));
17+
);
2018
}
2119

2220
/** @var SchemaExtensionInterface[] */
@@ -53,28 +51,4 @@ public function processExtensions()
5351

5452
return $this;
5553
}
56-
57-
private function addDefaultFallBackToTypeLoader(SchemaConfig $schemaConfig): SchemaConfig
58-
{
59-
$typeLoader = $schemaConfig->typeLoader;
60-
$loaderWrapper = null;
61-
$loaderWrapper = function ($name) use ($typeLoader, &$schemaConfig, &$loaderWrapper): ?Type {
62-
$type = null;
63-
try {
64-
$type = $typeLoader($name);
65-
} catch (UnresolvableException $e) {
66-
// second chance for types with un-registered name in TypeResolver
67-
// we disabled the custom typeLoader to force default loader usage
68-
$schemaConfig->typeLoader = null;
69-
$type = $this->getType($name);
70-
$schemaConfig->typeLoader = $loaderWrapper; // @phpstan-ignore-line
71-
}
72-
73-
return $type;
74-
};
75-
76-
$schemaConfig->typeLoader = $loaderWrapper; // @phpstan-ignore-line
77-
78-
return $schemaConfig;
79-
}
8054
}

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)