Skip to content

Commit c495e12

Browse files
Jeremiah VALERIEJeremiah VALERIE
authored andcommitted
Remove auto mapping configuration
This has been remove in favor of the Symfony 4+ service configuration.
1 parent 12179f5 commit c495e12

File tree

15 files changed

+75
-311
lines changed

15 files changed

+75
-311
lines changed

UPGRADE-0.12.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
UPGRADE FROM 0.11 to 0.12
2+
=======================
3+
4+
# Table of Contents
5+
6+
- [Remove auto mapping configuration](#remove-auto-mapping-configuration)
7+
8+
### Remove auto mapping configuration
9+
10+
* The AutoMapping configuration entry has been removed in favor of Symfony 4+ service configuration.
11+
12+
Upgrading:
13+
- Delete old configuration.
14+
```diff
15+
overblog_graphql:
16+
definitions:
17+
- auto_mapping: ~
18+
```
19+
- use Symfony 4+ service configuration to tag your types, resolvers or mutation.
20+
```yaml
21+
# config/graphql.yaml
22+
services:
23+
_defaults:
24+
autowire: true
25+
public: true
26+
27+
_instanceof:
28+
GraphQL\Type\Definition\Type:
29+
tags: ['overblog_graphql.type']
30+
Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface:
31+
tags: ['overblog_graphql.resolver']
32+
Overblog\GraphQLBundle\Definition\Resolver\MutationInterface:
33+
tags: ['overblog_graphql.mutation']
34+
35+
App\GraphQL\:
36+
resource: ../GraphQL
37+
```

docs/definitions/resolver.md

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -132,36 +132,18 @@ class CalcMutation implements MutationInterface, AliasedInterface
132132
`addition` mutation can be access by using `App\GraphQL\Mutation\CalcMutation::addition` or
133133
`add` alias.
134134

135-
You can also define custom dirs using the config (Symfony <3.3):
136-
```yaml
137-
overblog_graphql:
138-
definitions:
139-
auto_mapping:
140-
directories:
141-
- "%kernel.root_dir%/src/*Bundle/CustomDir"
142-
- "%kernel.root_dir%/src/AppBundle/{foo,bar}"
143-
```
144-
145-
If using Symfony 3.3+ disabling auto mapping can be a solution to leave place to native
146-
DI `autoconfigure`:
147-
148-
```yaml
149-
overblog_graphql:
150-
definitions:
151-
auto_mapping: false
152-
```
153-
154135
Here an example of how this can be done with DI `autoconfigure`:
155136

156137
```yaml
157138
services:
158-
App\Mutation\:
159-
resource: '../src/Mutation'
160-
tags: ['overblog_graphql.mutation']
161-
162-
App\Resolver\:
163-
resource: '../src/Resolver'
164-
tags: ['overblog_graphql.resolver']
139+
_instanceof:
140+
Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface:
141+
tags: ['overblog_graphql.resolver']
142+
Overblog\GraphQLBundle\Definition\Resolver\MutationInterface:
143+
tags: ['overblog_graphql.mutation']
144+
145+
Overblog\GraphQLBundle\GraphQL\Relay\:
146+
resource: ../../GraphQL/Relay/{Mutation,Node}
165147
```
166148

167149
## The service way

docs/definitions/type-system/index.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,6 @@ Types can be define 3 different ways:
6868
}
6969
```
7070

71-
You can also define custom dirs using config:
72-
```yaml
73-
overblog_graphql:
74-
definitions:
75-
auto_mapping:
76-
directories:
77-
- "%kernel.root_dir%/src/*Bundle/CustomDir"
78-
- "%kernel.root_dir%/src/AppBundle/{foo,bar}"
79-
```
80-
81-
If using Symfony 3.3+ disabling auto mapping can be a solution to leave place to native
82-
DI `autoconfigure`:
83-
84-
```yaml
85-
overblog_graphql:
86-
definitions:
87-
auto_mapping: false
88-
```
89-
9071
Here an example of how this can be done with DI `autoconfigure`:
9172

9273
```yaml

src/DependencyInjection/Compiler/AliasedPass.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22

33
namespace Overblog\GraphQLBundle\DependencyInjection\Compiler;
44

5+
use GraphQL\Type\Definition\Type;
56
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
7+
use Overblog\GraphQLBundle\Definition\Resolver\MutationInterface;
8+
use Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface;
69
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
710
use Symfony\Component\DependencyInjection\ContainerBuilder;
811
use Symfony\Component\DependencyInjection\Definition;
912

1013
final class AliasedPass implements CompilerPassInterface
1114
{
15+
private const SERVICE_SUBCLASS_TAG_MAPPING = [
16+
MutationInterface::class => 'overblog_graphql.mutation',
17+
ResolverInterface::class => 'overblog_graphql.resolver',
18+
Type::class => TypeTaggedServiceMappingPass::TAG_NAME,
19+
];
20+
1221
/**
1322
* {@inheritdoc}
1423
*/
@@ -28,7 +37,7 @@ public function process(ContainerBuilder $container)
2837
private function filterDefinitions($definitions)
2938
{
3039
return array_filter($definitions, function (Definition $definition) {
31-
foreach (AutoMappingPass::SERVICE_SUBCLASS_TAG_MAPPING as $tagName) {
40+
foreach (self::SERVICE_SUBCLASS_TAG_MAPPING as $tagName) {
3241
if ($definition->hasTag($tagName)) {
3342
return is_subclass_of($definition->getClass(), AliasedInterface::class);
3443
}
@@ -55,7 +64,7 @@ private function addDefinitionTagsFromAliases(Definition $definition)
5564
private function guessTagName(Definition $definition)
5665
{
5766
$tagName = null;
58-
foreach (AutoMappingPass::SERVICE_SUBCLASS_TAG_MAPPING as $refClassName => $tag) {
67+
foreach (self::SERVICE_SUBCLASS_TAG_MAPPING as $refClassName => $tag) {
5968
if (is_subclass_of($definition->getClass(), $refClassName)) {
6069
$tagName = $tag;
6170
break;

src/DependencyInjection/Compiler/AutoMappingPass.php

Lines changed: 0 additions & 185 deletions
This file was deleted.

src/DependencyInjection/Configuration.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ private function definitionsSection()
117117
->booleanNode('show_debug_info')->info('Show some performance stats in extensions')->defaultFalse()->end()
118118
->booleanNode('config_validation')->defaultValue($this->debug)->end()
119119
->append($this->definitionsSchemaSection())
120-
->append($this->definitionsAutoMappingSection())
121120
->append($this->definitionsMappingsSection())
122121
->arrayNode('builders')
123122
->children()
@@ -210,28 +209,6 @@ private function definitionsSchemaSection()
210209
return $node;
211210
}
212211

213-
private function definitionsAutoMappingSection()
214-
{
215-
$builder = new TreeBuilder();
216-
/** @var ArrayNodeDefinition $node */
217-
$node = $builder->root('auto_mapping');
218-
$node
219-
->treatFalseLike(['enabled' => false])
220-
->treatTrueLike(['enabled' => true])
221-
->treatNullLike(['enabled' => true])
222-
->addDefaultsIfNotSet()
223-
->children()
224-
->booleanNode('enabled')->defaultTrue()->end()
225-
->arrayNode('directories')
226-
->info('List of directories containing GraphQL classes.')
227-
->prototype('scalar')->end()
228-
->end()
229-
->end()
230-
->end();
231-
232-
return $node;
233-
}
234-
235212
private function definitionsMappingsSection()
236213
{
237214
$builder = new TreeBuilder();

src/DependencyInjection/OverblogGraphQLExtension.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ private function loadConfigFiles(ContainerBuilder $container)
7373
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
7474
$loader->load('services.yml');
7575
$loader->load('graphql_types.yml');
76+
$loader->load('graphql_resolvers.yml');
7677
$loader->load('expression_language_functions.yml');
7778
$loader->load('definition_config_processors.yml');
7879
}
@@ -106,9 +107,6 @@ private function setClassLoaderListener(array $config, ContainerBuilder $contain
106107

107108
private function setDefinitionParameters(array $config, ContainerBuilder $container)
108109
{
109-
// auto mapping
110-
$container->setParameter($this->getAlias().'.auto_mapping.enabled', $config['definitions']['auto_mapping']['enabled']);
111-
$container->setParameter($this->getAlias().'.auto_mapping.directories', $config['definitions']['auto_mapping']['directories']);
112110
// generator and config
113111
$container->setParameter($this->getAlias().'.default_resolver', $config['definitions']['default_resolver']);
114112
$container->setParameter($this->getAlias().'.class_namespace', $config['definitions']['class_namespace']);

src/DependencyInjection/OverblogGraphQLTypesExtension.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class OverblogGraphQLTypesExtension extends Extension
4242
public function load(array $configs, ContainerBuilder $container)
4343
{
4444
$configs = array_filter($configs);
45-
//$configs = array_filter($configs);
4645
if (count($configs) > 1) {
4746
throw new \InvalidArgumentException('Configs type should never contain more than one config to deal with inheritance.');
4847
}

0 commit comments

Comments
 (0)