Skip to content

Commit 55c3fd7

Browse files
authored
Make type namespaces available in RootTypeMapperFactoryContext (#605)
1 parent 6ce20bc commit 55c3fd7

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/Mappers/Root/RootTypeMapperFactoryContext.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111
use TheCodingMachine\GraphQLite\NamingStrategyInterface;
1212
use TheCodingMachine\GraphQLite\TypeRegistry;
1313
use TheCodingMachine\GraphQLite\Types\TypeResolver;
14+
use TheCodingMachine\GraphQLite\Utils\Namespaces\NS;
1415

1516
/**
1617
* A context class containing a number of classes created on the fly by SchemaFactory.
1718
* Those classes are made available to factories implementing RootTypeMapperFactoryInterface
1819
*/
1920
final class RootTypeMapperFactoryContext
2021
{
22+
/**
23+
* @param iterable<NS> $typeNamespaces
24+
*/
2125
public function __construct(
2226
private readonly AnnotationReader $annotationReader,
2327
private readonly TypeResolver $typeResolver,
@@ -26,6 +30,7 @@ public function __construct(
2630
private readonly RecursiveTypeMapperInterface $recursiveTypeMapper,
2731
private readonly ContainerInterface $container,
2832
private readonly CacheInterface $cache,
33+
private readonly iterable $typeNamespaces,
2934
private readonly int|null $globTTL,
3035
private readonly int|null $mapTTL = null,
3136
) {
@@ -66,6 +71,12 @@ public function getCache(): CacheInterface
6671
return $this->cache;
6772
}
6873

74+
/** @return iterable<NS> */
75+
public function getTypeNamespaces(): iterable
76+
{
77+
return $this->typeNamespaces;
78+
}
79+
6980
public function getGlobTTL(): int|null
7081
{
7182
return $this->globTTL;

src/SchemaFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ public function createSchema(): Schema
399399
$recursiveTypeMapper,
400400
$this->container,
401401
$namespacedCache,
402+
$nsList,
402403
$this->globTTL,
403404
);
404405

tests/RootTypeMapperFactoryContextTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Symfony\Component\Cache\Simple\ArrayCache;
99
use TheCodingMachine\GraphQLite\Containers\EmptyContainer;
1010
use TheCodingMachine\GraphQLite\Mappers\Root\RootTypeMapperFactoryContext;
11+
use TheCodingMachine\GraphQLite\Utils\Namespaces\NS;
1112

1213
class RootTypeMapperFactoryContextTest extends AbstractQueryProviderTest
1314
{
@@ -18,6 +19,7 @@ public function testContext(): void
1819
$namingStrategy = new NamingStrategy();
1920
$container = new EmptyContainer();
2021
$arrayCache = new Psr16Cache(new ArrayAdapter());
22+
$nsList = [$this->getNamespaceFactory()->createNamespace('namespace')];
2123

2224
$context = new RootTypeMapperFactoryContext(
2325
$this->getAnnotationReader(),
@@ -27,6 +29,7 @@ public function testContext(): void
2729
$this->getTypeMapper(),
2830
$container,
2931
$arrayCache,
32+
$nsList,
3033
self::GLOB_TTL_SECONDS
3134
);
3235

@@ -37,6 +40,8 @@ public function testContext(): void
3740
$this->assertSame($this->getTypeMapper(), $context->getRecursiveTypeMapper());
3841
$this->assertSame($container, $context->getContainer());
3942
$this->assertSame($arrayCache, $context->getCache());
43+
$this->assertSame($nsList, $context->getTypeNamespaces());
44+
$this->assertContainsOnlyInstancesOf(NS::class, $context->getTypeNamespaces());
4045
$this->assertSame(self::GLOB_TTL_SECONDS, $context->getGlobTTL());
4146
$this->assertNull($context->getMapTTL());
4247
}

0 commit comments

Comments
 (0)