Skip to content

Commit 7be3882

Browse files
authored
Merge pull request #279 from mcg-web/autoconfig-strict-aliases-requirements
Remove type resolver postLoad
2 parents fdf6b6a + 2e82d69 commit 7be3882

File tree

7 files changed

+117
-31
lines changed

7 files changed

+117
-31
lines changed

Resolver/AbstractResolver.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ private function loadSolution($name)
7777
$loader = $this->solutions[$name];
7878
$this->solutions[$name] = $loader();
7979
$this->fullyLoadedSolutions[$name] = true;
80-
$this->postLoadSolution($this->solutions[$name]);
8180

8281
return $this->solutions[$name];
8382
}
@@ -95,13 +94,6 @@ private function loadSolutions()
9594
return $this->solutions;
9695
}
9796

98-
/**
99-
* @param mixed $solution
100-
*/
101-
protected function postLoadSolution($solution)
102-
{
103-
}
104-
10597
/**
10698
* @param mixed $solution
10799
*

Resolver/TypeResolver.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,6 @@ private static function createTypeLoadingException($alias, $errorOrException)
113113
);
114114
}
115115

116-
protected function postLoadSolution($solution)
117-
{
118-
// also add solution with real type name if needed for typeLoader when using autoMapping
119-
if ($solution && !$this->hasSolution($solution->name)) {
120-
$this->addSolution($solution->name, function () use ($solution) {
121-
return $solution;
122-
}, [], ['id' => get_class($solution), 'alias' => $solution->name]);
123-
}
124-
}
125-
126116
protected function supportedSolutionClass()
127117
{
128118
return Type::class;

Resources/doc/definitions/resolver.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,13 @@ Resolvers can be define 2 different ways
123123

124124
```yaml
125125
services:
126-
_instanceof:
127-
GraphQL\Type\Definition\Type:
128-
tags: ['overblog_graphql.type']
129-
130126
App\Mutation\:
131127
resource: '../src/Mutation'
132128
tags: ['overblog_graphql.mutation']
133129

134130
App\Resolver\:
135131
resource: '../src/Resolver'
136132
tags: ['overblog_graphql.resolver']
137-
138-
App\Type\:
139-
resource: '../src/Type'
140133
```
141134

142135
**Note:**

Resources/doc/definitions/type-system/index.md

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,33 @@ Types can be define 3 different ways:
4141
You can also declare PHP types (any subclass of `GraphQL\Type\Definition\Type`)
4242
in `src/*Bundle/GraphQL` or `app/GraphQL`
4343
they will be auto discover (thanks to auto mapping). Auto map classes are accessible by FQCN
44-
(example: `AppBunble\GraphQL\Type\DateTimeType`), you can also alias type adding
45-
a public static function `getAliases`
44+
(example: `AppBunble\GraphQL\Type\DateTimeType`), you can also alias a type by
45+
implementing `Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface`
4646
that returns an array of aliases.
47+
48+
here an example:
49+
50+
```php
51+
<?php
52+
53+
namespace App\GraphQL\Type;
54+
55+
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
56+
use GraphQL\Type\Definition\ScalarType;
57+
58+
class DateTimeType extends ScalarType implements AliasedInterface
59+
{
60+
/**
61+
* {@inheritdoc}
62+
*/
63+
public static function getAliases()
64+
{
65+
return ['DateTime', 'Date'];
66+
}
67+
// ...
68+
}
69+
```
70+
4771
You can also define custom dirs using config:
4872
```yaml
4973
overblog_graphql:
@@ -53,13 +77,33 @@ Types can be define 3 different ways:
5377
- "%kernel.root_dir%/src/*Bundle/CustomDir"
5478
- "%kernel.root_dir%/src/AppBundle/{foo,bar}"
5579
```
56-
To disable auto mapping:
80+
81+
If using Symfony 3.3+ disabling auto mapping can be a solution to leave place to native
82+
DI `autoconfigure`:
83+
5784
```yaml
5885
overblog_graphql:
5986
definitions:
6087
auto_mapping: false
6188
```
6289

90+
Here an example of how this can be done with DI `autoconfigure`:
91+
92+
```yaml
93+
services:
94+
_instanceof:
95+
GraphQL\Type\Definition\Type:
96+
tags: ['overblog_graphql.type']
97+
98+
App\Type\:
99+
resource: '../src/Type'
100+
```
101+
102+
**Note:**
103+
* Types are lazy loaded so when using Symfony DI `autoconfigure` or this bundle auto mapping, the
104+
only access to type is FQCN (or aliases if implements the aliases interface).
105+
* When using FQCN in yaml definition, backslash must be correctly quotes,
106+
63107
3. **The service way**
64108

65109
Creating a service tagged `overblog_graphql.type`

Tests/Functional/App/GraphQL/HelloWord/Type/MutationType.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
use GraphQL\Type\Definition\ObjectType;
66
use GraphQL\Type\Definition\Type;
7+
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
78
use Overblog\GraphQLBundle\Resolver\MutationResolver;
89

9-
final class MutationType extends ObjectType
10+
final class MutationType extends ObjectType implements AliasedInterface
1011
{
1112
public function __construct(MutationResolver $mutator)
1213
{
@@ -29,4 +30,12 @@ public function __construct(MutationResolver $mutator)
2930
],
3031
]);
3132
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
public static function getAliases()
38+
{
39+
return ['Calc'];
40+
}
3241
}

Tests/Functional/App/GraphQL/HelloWord/Type/QueryType.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
use GraphQL\Type\Definition\ObjectType;
66
use GraphQL\Type\Definition\Type;
7+
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
78
use Overblog\GraphQLBundle\Resolver\ResolverResolver;
89
use Overblog\GraphQLBundle\Tests\Functional\App\IsolatedResolver\EchoResolver;
910

10-
final class QueryType extends ObjectType
11+
final class QueryType extends ObjectType implements AliasedInterface
1112
{
1213
public function __construct(ResolverResolver $resolver)
1314
{
@@ -29,4 +30,12 @@ public function __construct(ResolverResolver $resolver)
2930
],
3031
]);
3132
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
public static function getAliases()
38+
{
39+
return ['Query'];
40+
}
3241
}

UPGRADE-0.11.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ UPGRADE FROM 0.10 to 0.11
77
- [Errors handler](#errors-handler)
88
- [Promise adapter interface](#promise-adapter-interface)
99
- [Expression language](#expression-language)
10+
- [Type autoMapping and Symfony DI autoconfigure](#type-automapping-and-symfony-di-autoconfigure)
1011

1112
### GraphiQL
1213

@@ -49,7 +50,6 @@ UPGRADE FROM 0.10 to 0.11
4950
* Made errors handler more customizable
5051

5152
Upgrading:
52-
- User
5353
- Delete configuration to override base user exception classes.
5454
```diff
5555
overblog_graphql:
@@ -129,3 +129,52 @@ UPGRADE FROM 0.10 to 0.11
129129
- resolve: '@=resolver('foo', [request])'
130130
+ resolve: '@=resolver('foo', [serv('request_stack')])'
131131
```
132+
### Type autoMapping and Symfony DI `autoconfigure`
133+
134+
When using these functionality, type will be accessible only by FQCN in schema definition,
135+
(if class not implementing `Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface`).
136+
So if you want to use the `true` type name don't forget to declare it as an alias using interface.
137+
This change is for a performance mater types are lazy loaded.
138+
139+
example:
140+
141+
```php
142+
<?php
143+
144+
namespace App\GraphQL\Type;
145+
146+
use GraphQL\Type\Definition\ScalarType;
147+
148+
class DateTimeType extends ScalarType
149+
{
150+
public $name = 'DateTme';
151+
// ...
152+
}
153+
```
154+
**Before 0.11**: DateTimeType could be accessed by FQCN `App\GraphQL\Type\DateTimeType` and the real `DateTimeType`.
155+
**Since 0.11**: Only FQCN `App\GraphQL\Type\DateTimeType` is accessible
156+
157+
here how this can be done in 0.11:
158+
159+
```php
160+
<?php
161+
162+
namespace App\GraphQL\Type;
163+
164+
use GraphQL\Type\Definition\ScalarType;
165+
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
166+
167+
class DateTimeType extends ScalarType implements AliasedInterface
168+
{
169+
public $name = 'DateTme';
170+
171+
/**
172+
* {@inheritdoc}
173+
*/
174+
public static function getAliases()
175+
{
176+
return ['DateTime'];
177+
}
178+
// ...
179+
}
180+
```

0 commit comments

Comments
 (0)