Skip to content

Commit bee2e36

Browse files
author
Jeremiah VALERIE
committed
Merge branch '0.14'
2 parents c29a4b8 + 783018e commit bee2e36

File tree

9 files changed

+31
-95
lines changed

9 files changed

+31
-95
lines changed

src/DependencyInjection/Compiler/TaggedServiceMappingPass.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Overblog\GraphQLBundle\DependencyInjection\Compiler;
66

77
use InvalidArgumentException;
8+
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
89
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
910
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
1011
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -63,13 +64,11 @@ public function process(ContainerBuilder $container): void
6364
$serviceID = $attributes['id'];
6465

6566
$solutionDefinition = $container->findDefinition($serviceID);
66-
// make solution service public to improve lazy loading
67-
$solutionDefinition->setPublic(true);
6867
$this->autowireSolutionImplementingContainerAwareInterface($solutionDefinition, empty($attributes['generated']));
6968

7069
$resolverDefinition->addMethodCall(
7170
'addSolution',
72-
[$solutionID, [[new Reference('service_container'), 'get'], [$serviceID]], $aliases, $attributes]
71+
[$solutionID, new ServiceClosureArgument(new Reference($serviceID)), $aliases, $attributes]
7372
);
7473
}
7574
}

src/DependencyInjection/Configuration.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition;
2020
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
2121
use Symfony\Component\Config\Definition\ConfigurationInterface;
22+
use Symfony\Component\HttpKernel\Kernel;
2223
use function array_keys;
2324
use function is_array;
2425
use function is_int;
@@ -31,15 +32,13 @@ class Configuration implements ConfigurationInterface
3132
public const NAME = 'overblog_graphql';
3233

3334
private bool $debug;
34-
private ?string $cacheDir;
3535

3636
/**
3737
* @param bool $debug Whether to use the debug mode
3838
*/
39-
public function __construct(bool $debug, string $cacheDir = null)
39+
public function __construct(bool $debug)
4040
{
41-
$this->debug = (bool) $debug;
42-
$this->cacheDir = $cacheDir;
41+
$this->debug = $debug;
4342
}
4443

4544
public function getConfigTreeBuilder(): TreeBuilder
@@ -207,6 +206,16 @@ private function definitionsSchemaSection(): ArrayNodeDefinition
207206
/** @var ArrayNodeDefinition $node */
208207
$node = $builder->getRootNode();
209208

209+
if (Kernel::VERSION_ID >= 50100) {
210+
$deprecatedArgs = [
211+
'overblog/graphql-bundle',
212+
'0.13',
213+
'The "%path%.%node%" configuration is deprecated and will be removed in 1.0. Add the "overblog_graphql.resolver_map" tag to the services instead.',
214+
];
215+
} else {
216+
$deprecatedArgs = ['The "%path%.%node%" configuration is deprecated since version 0.13 and will be removed in 1.0. Add the "overblog_graphql.resolver_map" tag to the services instead.'];
217+
}
218+
210219
// @phpstan-ignore-next-line
211220
$node
212221
->beforeNormalization()
@@ -223,7 +232,7 @@ private function definitionsSchemaSection(): ArrayNodeDefinition
223232
->arrayNode('resolver_maps')
224233
->defaultValue([])
225234
->prototype('scalar')->end()
226-
->setDeprecated('The "%path%.%node%" configuration is deprecated since version 0.13 and will be removed in 1.0. Add the "overblog_graphql.resolver_map" tag to the services instead.')
235+
->setDeprecated(...$deprecatedArgs)
227236
->end()
228237
->arrayNode('types')
229238
->defaultValue([])

src/DependencyInjection/OverblogGraphQLExtension.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ public function getConfiguration(array $config, ContainerBuilder $container): Co
7070
{
7171
return new Configuration(
7272
// @phpstan-ignore-next-line
73-
$container->getParameter('kernel.debug'),
74-
// @phpstan-ignore-next-line
75-
$container->hasParameter('kernel.cache_dir') ? $container->getParameter('kernel.cache_dir') : null
73+
$container->getParameter('kernel.debug')
7674
);
7775
}
7876

src/Resolver/AbstractResolver.php

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44

55
namespace Overblog\GraphQLBundle\Resolver;
66

7-
use GraphQL\Type\Definition\Type;
87
use function array_keys;
9-
use function call_user_func_array;
10-
use function get_class;
11-
use function is_array;
12-
use function is_callable;
13-
use function sprintf;
148

159
abstract class AbstractResolver implements FluentResolverInterface
1610
{
@@ -19,23 +13,12 @@ abstract class AbstractResolver implements FluentResolverInterface
1913
private array $solutionOptions = [];
2014
private array $fullyLoadedSolutions = [];
2115

22-
public function addSolution(string $id, $solutionOrFactory, array $aliases = [], array $options = []): self
16+
public function addSolution(string $id, callable $factory, array $aliases = [], array $options = []): self
2317
{
2418
$this->fullyLoadedSolutions[$id] = false;
2519
$this->addAliases($id, $aliases);
2620

27-
$this->solutions[$id] = function () use ($id, $solutionOrFactory) {
28-
$solution = $solutionOrFactory;
29-
if (self::isSolutionFactory($solutionOrFactory)) {
30-
if (!isset($solutionOrFactory[1])) {
31-
$solutionOrFactory[1] = [];
32-
}
33-
$solution = call_user_func_array(...$solutionOrFactory);
34-
}
35-
$this->checkSolution($id, $solution);
36-
37-
return $solution;
38-
};
21+
$this->solutions[$id] = $factory;
3922
$this->solutionOptions[$id] = $options;
4023

4124
return $this;
@@ -78,7 +61,7 @@ public function getSolutionOptions(string $id)
7861
{
7962
$id = $this->resolveAlias($id);
8063

81-
return isset($this->solutionOptions[$id]) ? $this->solutionOptions[$id] : [];
64+
return $this->solutionOptions[$id] ?? [];
8265
}
8366

8467
/**
@@ -117,17 +100,9 @@ private function addAliases(string $id, array $aliases): void
117100
}
118101
}
119102

120-
/**
121-
* @param object|array $solutionOrFactory
122-
*/
123-
private static function isSolutionFactory($solutionOrFactory): bool
124-
{
125-
return is_array($solutionOrFactory) && isset($solutionOrFactory[0]) && is_callable($solutionOrFactory[0]);
126-
}
127-
128103
private function resolveAlias(string $alias): string
129104
{
130-
return isset($this->aliases[$alias]) ? $this->aliases[$alias] : $alias;
105+
return $this->aliases[$alias] ?? $alias;
131106
}
132107

133108
/**
@@ -141,36 +116,4 @@ private function loadSolutions(): array
141116

142117
return $this->solutions;
143118
}
144-
145-
/**
146-
* @param mixed $solution
147-
*/
148-
protected function supportsSolution($solution): bool
149-
{
150-
$supportedClass = $this->supportedSolutionClass();
151-
152-
return null === $supportedClass || $solution instanceof $supportedClass;
153-
}
154-
155-
/**
156-
* @param mixed $solution
157-
*/
158-
protected function checkSolution(string $id, $solution): void
159-
{
160-
if (!$this->supportsSolution($solution)) {
161-
throw new UnsupportedResolverException(
162-
sprintf('Resolver "%s" must be "%s" "%s" given.', $id, $this->supportedSolutionClass(), get_class($solution))
163-
);
164-
}
165-
}
166-
167-
/**
168-
* default return null to accept mixed type.
169-
*
170-
* @return string|null supported class name
171-
*/
172-
protected function supportedSolutionClass(): ?string
173-
{
174-
return null;
175-
}
176119
}

src/Resolver/FluentResolverInterface.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ public function resolve($input);
1616
/**
1717
* Add a solution to resolver.
1818
*
19-
* @param string $id the solution identifier
20-
* @param array|mixed $solutionOrFactory the solution itself or array with a factory and it arguments if needed [$factory] or [$factory, $factoryArgs]
21-
* @param string[] $aliases the solution aliases
22-
* @param array $options extra options
19+
* @param string $id the solution identifier
20+
* @param callable $factory the solution factory
21+
* @param string[] $aliases the solution aliases
22+
* @param array $options extra options
2323
*
2424
* @return $this
2525
*/
26-
public function addSolution(string $id, $solutionOrFactory, array $aliases = [], array $options = []): self;
26+
public function addSolution(string $id, callable $factory, array $aliases = [], array $options = []): self;
2727

2828
/**
2929
* @return mixed

tests/DependencyInjection/Compiler/ResolverTaggedServiceMappingPassTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function testCompilationWorksPassConfigDirective(): void
4040
{
4141
$testResolver = new Definition(ResolverTestService::class);
4242
$testResolver
43+
->setPublic(true)
4344
->addTag('overblog_graphql.query', [
4445
'alias' => 'test_resolver', 'method' => 'doSomethingWithContainer',
4546
]);

tests/Functional/App/config/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ framework:
33
secret: test
44
router:
55
resource: "%kernel.project_dir%/config/routing.yml"
6+
utf8: true
67
profiler:
78
enabled: false
89

tests/Resolver/AbstractProxyResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract class AbstractProxyResolverTest extends AbstractResolverTest
1212
protected function getResolverSolutionsMapping(): array
1313
{
1414
return [
15-
'Toto' => ['factory' => [[$this, 'createToto'], []], 'aliases' => ['foo', 'bar', 'baz'], 'method' => 'resolve'],
15+
'Toto' => ['factory' => [$this, 'createToto'], 'aliases' => ['foo', 'bar', 'baz'], 'method' => 'resolve'],
1616
];
1717
}
1818

tests/Resolver/TypeResolverTest.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
namespace Overblog\GraphQLBundle\Tests\Resolver;
66

77
use GraphQL\Type\Definition\ObjectType;
8-
use GraphQL\Type\Definition\Type;
98
use Overblog\GraphQLBundle\Resolver\TypeResolver;
109
use Overblog\GraphQLBundle\Resolver\UnresolvableException;
11-
use Overblog\GraphQLBundle\Resolver\UnsupportedResolverException;
12-
use stdClass;
13-
use function sprintf;
1410

1511
class TypeResolverTest extends AbstractResolverTest
1612
{
@@ -22,8 +18,8 @@ protected function createResolver(): TypeResolver
2218
protected function getResolverSolutionsMapping(): array
2319
{
2420
return [
25-
'Toto' => ['factory' => [[$this, 'createObjectType'], [['name' => 'Toto']]], 'aliases' => ['foo']],
26-
'Tata' => ['factory' => [[$this, 'createObjectType'], [['name' => 'Tata']]], 'aliases' => ['bar']],
21+
'Toto' => ['factory' => fn () => $this->createObjectType(['name' => 'Toto']), 'aliases' => ['foo']],
22+
'Tata' => ['factory' => fn () => $this->createObjectType(['name' => 'Tata']), 'aliases' => ['bar']],
2723
];
2824
}
2925

@@ -32,17 +28,6 @@ public function createObjectType(array $config): ObjectType
3228
return new ObjectType($config);
3329
}
3430

35-
public function testAddNotSupportedSolution(): void
36-
{
37-
$this->expectException(UnsupportedResolverException::class);
38-
$this->expectExceptionMessage(sprintf(
39-
'Resolver "not-supported" must be "%s" "stdClass" given.',
40-
Type::class
41-
));
42-
$this->resolver->addSolution('not-supported', new stdClass());
43-
$this->resolver->getSolution('not-supported');
44-
}
45-
4631
public function testResolveKnownType(): void
4732
{
4833
$type = $this->resolver->resolve('Toto');

0 commit comments

Comments
 (0)