Skip to content

Commit 4a63abd

Browse files
authored
Merge pull request #251 from cvergne/fix/247-statictypemapper-methods-to-constructor
[Fix] Fix StaticTypeMapper method calls by moving definition
2 parents 6af6ed5 + 833ed71 commit 4a63abd

File tree

5 files changed

+51
-12
lines changed

5 files changed

+51
-12
lines changed

src/DependencyInjection/GraphQLiteCompilerPass.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,12 @@ public function process(ContainerBuilder $container): void
271271
}
272272
}
273273

274-
if (!empty($customTypes)) {
275-
$definition = $container->getDefinition(StaticTypeMapper::class);
276-
$definition->addMethodCall('setTypes', [$customTypes]);
277-
}
278-
if (!empty($customNotMappedTypes)) {
279-
$definition = $container->getDefinition(StaticTypeMapper::class);
280-
$definition->addMethodCall('setNotMappedTypes', [$customNotMappedTypes]);
281-
}
274+
$staticMapperDefinition = new Definition(StaticTypeMapper::class, [
275+
'$types' => $customTypes,
276+
'$notMappedTypes' => $customNotMappedTypes
277+
]);
278+
$staticMapperDefinition->addTag('graphql.type_mapper');
279+
$container->setDefinition(StaticTypeMapper::class, $staticMapperDefinition);
282280

283281
// Register graphql.queryprovider
284282
$this->mapAdderToTag('graphql.queryprovider', 'addQueryProvider', $container, $schemaFactory);

src/Resources/config/container/graphqlite.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@
7979

8080
<service id="GraphQL\Validator\Rules\QueryDepth" />
8181

82-
<service id="TheCodingMachine\GraphQLite\Mappers\StaticTypeMapper">
83-
<tag name="graphql.type_mapper"/>
84-
</service>
85-
8682
<service id="TheCodingMachine\GraphQLite\Bundle\Controller\GraphQLiteController" public="true">
8783
<tag name="routing.route_loader"/>
8884
</service>

tests/Fixtures/Entities/Book.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace TheCodingMachine\GraphQLite\Bundle\Tests\Fixtures\Entities;
4+
5+
class Book
6+
{
7+
public function __construct(
8+
private readonly string $title
9+
)
10+
{
11+
}
12+
13+
public function getTitle(): string
14+
{
15+
return $this->title;
16+
}
17+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace TheCodingMachine\GraphQLite\Bundle\Tests\Fixtures\Types;
4+
5+
use GraphQL\Type\Definition\ObjectType;
6+
use GraphQL\Type\Definition\Type;
7+
8+
class CustomBookType extends ObjectType
9+
{
10+
public function __construct()
11+
{
12+
parent::__construct([
13+
'name' => 'Book',
14+
'description' => 'A book',
15+
'fields' => [
16+
'title' => [
17+
'type' => Type::nonNull(Type::string()),
18+
'description' => 'Book title',
19+
],
20+
],
21+
]);
22+
}
23+
24+
}

tests/Fixtures/config/services.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ services:
2020
TheCodingMachine\GraphQLite\Bundle\Tests\NoSecurityBundleFixtures\:
2121
resource: '../../NoSecurityBundleFixtures/*'
2222

23+
TheCodingMachine\Graphqlite\Bundle\Tests\Fixtures\Types\CustomBookType:
24+
tags:
25+
- { name: 'graphql.output_type', class: 'TheCodingMachine\GraphQLite\Bundle\Tests\Fixtures\Entities\Book' }
26+
2327
someService:
2428
class: stdClass
2529

0 commit comments

Comments
 (0)