diff --git a/Resolver/AbstractResolver.php b/Resolver/AbstractResolver.php index 1e11281e7..0442cebcf 100644 --- a/Resolver/AbstractResolver.php +++ b/Resolver/AbstractResolver.php @@ -2,6 +2,8 @@ namespace Overblog\GraphQLBundle\Resolver; +use Symfony\Component\HttpKernel\Kernel; + abstract class AbstractResolver implements FluentResolverInterface { /** @var array */ @@ -15,8 +17,17 @@ abstract class AbstractResolver implements FluentResolverInterface /** @var array */ private $fullyLoadedSolutions = []; + /** @var bool */ + private $ignoreCase = true; + + public function __construct() + { + $this->ignoreCase = version_compare(Kernel::VERSION, '3.3.0') < 0; + } + public function addSolution($id, $solutionOrFactory, array $aliases = [], array $options = []) { + $id = $this->cleanIdOrAlias($id); $this->fullyLoadedSolutions[$id] = false; $this->addAliases($id, $aliases); @@ -105,7 +116,7 @@ private function loadSolution($id) private function addAliases($id, $aliases) { foreach ($aliases as $alias) { - $this->aliases[$alias] = $id; + $this->aliases[$this->cleanIdOrAlias($alias)] = $id; } } @@ -116,9 +127,16 @@ private static function isSolutionFactory($solutionOrFactory) private function resolveAlias($alias) { + $alias = $this->cleanIdOrAlias($alias); + return isset($this->aliases[$alias]) ? $this->aliases[$alias] : $alias; } + private function cleanIdOrAlias($idOrAlias) + { + return $this->ignoreCase ? strtolower($idOrAlias) : $idOrAlias; + } + /** * @return mixed[] */ diff --git a/Resolver/TypeResolver.php b/Resolver/TypeResolver.php index a85957b0a..6ecaa5ae9 100644 --- a/Resolver/TypeResolver.php +++ b/Resolver/TypeResolver.php @@ -3,18 +3,10 @@ namespace Overblog\GraphQLBundle\Resolver; use GraphQL\Type\Definition\Type; -use Psr\Cache\CacheItemPoolInterface; -use Symfony\Component\Cache\Adapter\ArrayAdapter; class TypeResolver extends AbstractResolver { - /** @var CacheItemPoolInterface */ - private $cacheAdapter; - - public function __construct(CacheItemPoolInterface $cacheAdapter = null) - { - $this->cacheAdapter = null !== $cacheAdapter ? $cacheAdapter : new ArrayAdapter(0, false); - } + private $cache = []; /** * @param string $alias @@ -26,15 +18,13 @@ public function resolve($alias) if (null === $alias) { return; } - $item = $this->cacheAdapter->getItem(md5($alias)); - if (!$item->isHit()) { + if (!isset($this->cache[$alias])) { $type = $this->string2Type($alias); - $item->set($type); - $this->cacheAdapter->save($item); + $this->cache[$alias] = $type; } - return $item->get(); + return $this->cache[$alias]; } private function string2Type($alias) diff --git a/Resources/config/services.yml b/Resources/config/services.yml index cb1902ecf..e8e1d307f 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -38,8 +38,6 @@ services: overblog_graphql.type_resolver: class: Overblog\GraphQLBundle\Resolver\TypeResolver public: true - arguments: - - tags: - { name: overblog_graphql.global_variable, alias: typeResolver } diff --git a/Resources/doc/definitions/resolver.md b/Resources/doc/definitions/resolver.md index a852c96d4..d926ebde4 100644 --- a/Resources/doc/definitions/resolver.md +++ b/Resources/doc/definitions/resolver.md @@ -15,8 +15,8 @@ Resolvers can be define 2 different ways or `Overblog\GraphQLBundle\Definition\Resolver\MutationInterface`) in `src/*Bundle/GraphQL` or `app/GraphQL` and they will be auto discovered. Auto map classes method are accessible by: - * double colon (::) to separate service id (class name) and the method names - (example: `AppBunble\GraphQL\CustomResolver::myMethod` or `appbunble\graphql\customresolver::myMethod` for Symfony < 3.3) + * double-colon (::) to separate service id (class name) and the method names + (example: `AppBunble\GraphQL\CustomResolver::myMethod`) * for callable classes you can use the service id (example: `AppBunble\GraphQL\InvokeResolver` for a resolver implementing the `__invoke` method) you can also alias a type by implementing `Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface` 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 ``` **Note:** - * When using service id as FQCN in yaml definition, backslash must be correctly quotes, + * When using service id as FQCN in yaml definition, backslashes must be correctly escaped, here an example `'@=resolver("App\\GraphQL\\Resolver\\Greetings", [args['name']])'`. * You can also see the more straight forward way using [resolver map](resolver-map.md) diff --git a/Resources/doc/definitions/type-system/index.md b/Resources/doc/definitions/type-system/index.md index 05ba9551d..c6bf02263 100644 --- a/Resources/doc/definitions/type-system/index.md +++ b/Resources/doc/definitions/type-system/index.md @@ -102,7 +102,7 @@ Types can be define 3 different ways: **Note:** * Types are lazy loaded so when using Symfony DI `autoconfigure` or this bundle auto mapping, the only access to type is FQCN (or aliases if implements the aliases interface). - * When using service id as FQCN in yaml definition, backslash must be correctly quotes, + * When using service id as FQCN in yaml definition, backslashes must be correctly escaped, 3. **The service way** diff --git a/Tests/Functional/App/GraphQL/HelloWord/Type/QueryType.php b/Tests/Functional/App/GraphQL/HelloWord/Type/QueryType.php index b82e78d76..26e8008d7 100644 --- a/Tests/Functional/App/GraphQL/HelloWord/Type/QueryType.php +++ b/Tests/Functional/App/GraphQL/HelloWord/Type/QueryType.php @@ -7,7 +7,6 @@ use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface; use Overblog\GraphQLBundle\Resolver\ResolverResolver; use Overblog\GraphQLBundle\Tests\Functional\App\IsolatedResolver\EchoResolver; -use Symfony\Component\HttpKernel\Kernel; final class QueryType extends ObjectType implements AliasedInterface { @@ -22,10 +21,7 @@ public function __construct(ResolverResolver $resolver) 'message' => ['type' => Type::string()], ], 'resolve' => function ($root, $args) use ($resolver) { - return $resolver->resolve([ - version_compare(Kernel::VERSION, '3.3.0') < 0 ? strtolower(EchoResolver::class) : EchoResolver::class, - [$args['message']], - ]); + return $resolver->resolve([EchoResolver::class, [$args['message']]]); }, ], ], diff --git a/UPGRADE-0.11.md b/UPGRADE-0.11.md index de0aa3f00..5a6797406 100644 --- a/UPGRADE-0.11.md +++ b/UPGRADE-0.11.md @@ -258,8 +258,8 @@ UPGRADE FROM 0.10 to 0.11 ### Change fluent resolvers id The use of class name as prefix of fluent resolver id remove the possibility to use same class as 2 different services. - see this [issue for more detail](https://github.com/overblog/GraphQLBundle/issues/296) - That the reason from 0.11 we using service id as prefix (like in Symfony 4.1)... + See issue [#296](https://github.com/overblog/GraphQLBundle/issues/296) for more detail + That's the reason why starting v0.11 we are using service id as prefix (like in Symfony 4.1)... Example: ```yaml diff --git a/composer.json b/composer.json index dbc97cdd5..ec8825850 100644 --- a/composer.json +++ b/composer.json @@ -30,9 +30,8 @@ }, "require": { "php": ">=5.6", - "doctrine/doctrine-cache-bundle": "^1.2", "overblog/graphql-php-generator": "^0.7.0", - "symfony/cache": "^3.1 || ^4.0", + "psr/log": "^1.0", "symfony/config": "^3.1 || ^4.0", "symfony/dependency-injection": "^3.1 || ^4.0", "symfony/event-dispatcher": "^3.1 || ^4.0", @@ -49,7 +48,6 @@ }, "require-dev": { "phpunit/phpunit": "^5.7.26 || ^6.0", - "psr/log": "^1.0", "react/promise": "^2.5", "sensio/framework-extra-bundle": "^3.0", "symfony/asset": "^3.1 || ^4.0",