Skip to content

Commit 04e48ae

Browse files
author
Jeremiah VALERIE
committed
Fix review feedback
1 parent 7c887f8 commit 04e48ae

File tree

8 files changed

+31
-31
lines changed

8 files changed

+31
-31
lines changed

Resolver/AbstractResolver.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Overblog\GraphQLBundle\Resolver;
44

5+
use Symfony\Component\HttpKernel\Kernel;
6+
57
abstract class AbstractResolver implements FluentResolverInterface
68
{
79
/** @var array */
@@ -15,8 +17,17 @@ abstract class AbstractResolver implements FluentResolverInterface
1517
/** @var array */
1618
private $fullyLoadedSolutions = [];
1719

20+
/** @var bool */
21+
private $ignoreCase = true;
22+
23+
public function __construct()
24+
{
25+
$this->ignoreCase = version_compare(Kernel::VERSION, '3.3.0') < 0;
26+
}
27+
1828
public function addSolution($id, $solutionOrFactory, array $aliases = [], array $options = [])
1929
{
30+
$id = $this->cleanIdOrAlias($id);
2031
$this->fullyLoadedSolutions[$id] = false;
2132
$this->addAliases($id, $aliases);
2233

@@ -105,7 +116,7 @@ private function loadSolution($id)
105116
private function addAliases($id, $aliases)
106117
{
107118
foreach ($aliases as $alias) {
108-
$this->aliases[$alias] = $id;
119+
$this->aliases[$this->cleanIdOrAlias($alias)] = $id;
109120
}
110121
}
111122

@@ -116,9 +127,16 @@ private static function isSolutionFactory($solutionOrFactory)
116127

117128
private function resolveAlias($alias)
118129
{
130+
$alias = $this->cleanIdOrAlias($alias);
131+
119132
return isset($this->aliases[$alias]) ? $this->aliases[$alias] : $alias;
120133
}
121134

135+
private function cleanIdOrAlias($idOrAlias)
136+
{
137+
return $this->ignoreCase ? strtolower($idOrAlias) : $idOrAlias;
138+
}
139+
122140
/**
123141
* @return mixed[]
124142
*/

Resolver/TypeResolver.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,10 @@
33
namespace Overblog\GraphQLBundle\Resolver;
44

55
use GraphQL\Type\Definition\Type;
6-
use Psr\Cache\CacheItemPoolInterface;
7-
use Symfony\Component\Cache\Adapter\ArrayAdapter;
86

97
class TypeResolver extends AbstractResolver
108
{
11-
/** @var CacheItemPoolInterface */
12-
private $cacheAdapter;
13-
14-
public function __construct(CacheItemPoolInterface $cacheAdapter = null)
15-
{
16-
$this->cacheAdapter = null !== $cacheAdapter ? $cacheAdapter : new ArrayAdapter(0, false);
17-
}
9+
private $cache = [];
1810

1911
/**
2012
* @param string $alias
@@ -26,15 +18,13 @@ public function resolve($alias)
2618
if (null === $alias) {
2719
return;
2820
}
29-
$item = $this->cacheAdapter->getItem(md5($alias));
3021

31-
if (!$item->isHit()) {
22+
if (!isset($this->cache[$alias])) {
3223
$type = $this->string2Type($alias);
33-
$item->set($type);
34-
$this->cacheAdapter->save($item);
24+
$this->cache[$alias] = $type;
3525
}
3626

37-
return $item->get();
27+
return $this->cache[$alias];
3828
}
3929

4030
private function string2Type($alias)

Resources/config/services.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ services:
3838
overblog_graphql.type_resolver:
3939
class: Overblog\GraphQLBundle\Resolver\TypeResolver
4040
public: true
41-
arguments:
42-
-
4341
tags:
4442
- { name: overblog_graphql.global_variable, alias: typeResolver }
4543

Resources/doc/definitions/resolver.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Resolvers can be define 2 different ways
1515
or `Overblog\GraphQLBundle\Definition\Resolver\MutationInterface`)
1616
in `src/*Bundle/GraphQL` or `app/GraphQL` and they will be auto discovered.
1717
Auto map classes method are accessible by:
18-
* double colon (::) to separate service id (class name) and the method names
19-
(example: `AppBunble\GraphQL\CustomResolver::myMethod` or `appbunble\graphql\customresolver::myMethod` for Symfony < 3.3)
18+
* double-colon (::) to separate service id (class name) and the method names
19+
(example: `AppBunble\GraphQL\CustomResolver::myMethod`)
2020
* for callable classes you can use the service id (example: `AppBunble\GraphQL\InvokeResolver` for a resolver implementing the `__invoke` method)
2121
you can also alias a type by implementing `Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface`
2222
which returns a map of method/alias. The service created will autowire the `__construct`
@@ -134,7 +134,7 @@ Resolvers can be define 2 different ways
134134
```
135135

136136
**Note:**
137-
* When using service id as FQCN in yaml definition, backslash must be correctly quotes,
137+
* When using service id as FQCN in yaml definition, backslashes must be correctly escaped,
138138
here an example `'@=resolver("App\\GraphQL\\Resolver\\Greetings", [args['name']])'`.
139139
* You can also see the more straight forward way using [resolver map](resolver-map.md)
140140

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Types can be define 3 different ways:
102102
**Note:**
103103
* Types are lazy loaded so when using Symfony DI `autoconfigure` or this bundle auto mapping, the
104104
only access to type is FQCN (or aliases if implements the aliases interface).
105-
* When using service id as FQCN in yaml definition, backslash must be correctly quotes,
105+
* When using service id as FQCN in yaml definition, backslashes must be correctly escaped,
106106

107107
3. **The service way**
108108

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
88
use Overblog\GraphQLBundle\Resolver\ResolverResolver;
99
use Overblog\GraphQLBundle\Tests\Functional\App\IsolatedResolver\EchoResolver;
10-
use Symfony\Component\HttpKernel\Kernel;
1110

1211
final class QueryType extends ObjectType implements AliasedInterface
1312
{
@@ -22,10 +21,7 @@ public function __construct(ResolverResolver $resolver)
2221
'message' => ['type' => Type::string()],
2322
],
2423
'resolve' => function ($root, $args) use ($resolver) {
25-
return $resolver->resolve([
26-
version_compare(Kernel::VERSION, '3.3.0') < 0 ? strtolower(EchoResolver::class) : EchoResolver::class,
27-
[$args['message']],
28-
]);
24+
return $resolver->resolve([EchoResolver::class, [$args['message']]]);
2925
},
3026
],
3127
],

UPGRADE-0.11.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ UPGRADE FROM 0.10 to 0.11
258258
### Change fluent resolvers id
259259

260260
The use of class name as prefix of fluent resolver id remove the possibility to use same class as 2 different services.
261-
see this [issue for more detail](https://github.com/overblog/GraphQLBundle/issues/296)
262-
That the reason from 0.11 we using service id as prefix (like in Symfony 4.1)...
261+
See issue [#296](https://github.com/overblog/GraphQLBundle/issues/296) for more detail
262+
That's the reason why starting v0.11 we are using service id as prefix (like in Symfony 4.1)...
263263

264264
Example:
265265
```yaml

composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030
},
3131
"require": {
3232
"php": ">=5.6",
33-
"doctrine/doctrine-cache-bundle": "^1.2",
3433
"overblog/graphql-php-generator": "^0.7.0",
35-
"symfony/cache": "^3.1 || ^4.0",
34+
"psr/log": "^1.0",
3635
"symfony/config": "^3.1 || ^4.0",
3736
"symfony/dependency-injection": "^3.1 || ^4.0",
3837
"symfony/event-dispatcher": "^3.1 || ^4.0",
@@ -49,7 +48,6 @@
4948
},
5049
"require-dev": {
5150
"phpunit/phpunit": "^5.7.26 || ^6.0",
52-
"psr/log": "^1.0",
5351
"react/promise": "^2.5",
5452
"sensio/framework-extra-bundle": "^3.0",
5553
"symfony/asset": "^3.1 || ^4.0",

0 commit comments

Comments
 (0)