Skip to content

Commit f8716d7

Browse files
committed
Add deprecations
1 parent 1f44eef commit f8716d7

File tree

15 files changed

+200
-37
lines changed

15 files changed

+200
-37
lines changed

UPGRADE-1.0.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ $connectionBuilder = new ConnectionBuilder(
4040
### Change arguments of `TypeGenerator` class
4141

4242
The `Overblog\GraphQLBundle\Generator\TypeGenerator` service is used internally for GraphQL types compilation. If you
43-
overridden the service definition, please take into account the new constructor signature:
43+
overrode the service definition, please take into account the new constructor signature:
4444

4545
```diff
4646
public function __construct(
@@ -104,31 +104,33 @@ If you have any services tagged with `overblog_graphql.global_variable`, they sh
104104
`overblog_graphql.graphql_service` instead.
105105

106106

107-
## Change `resolver` expression function
107+
### Change `resolver` expression function
108108

109109
The signature of the `resolver` expression function has been changed.
110110

111111
Old signature (deprecated): <code><b>resolver</b>(string <b>$alias</b>, array <b>$args</b> = []): mixed</code>
112112
New signature: <code><b>query</b>(string <b>$alias</b>, <b>...$args</b>): mixed</code>
113113

114-
Example of the function call to be changed:
114+
Example:
115115
```diff
116116
- resolver('get_posts', [args, info, value])
117117
+ query('get_posts', args, info, value)
118118
```
119119

120120

121-
## Rename `ResolverInterface` to `QueryInterface`
121+
### Rename `ResolverInterface` to `QueryInterface`
122122

123123
The `Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface` interface is deprecated. Use
124124
`Overblog\GraphQLBundle\Definition\Resolver\QueryInterface` instead.
125125

126126
Example:
127127
```diff
128128
- use Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface;
129-
-
130-
- class UserResolver implements ResolverInterface
131129
+ use Overblog\GraphQLBundle\Definition\Resolver\QueryInterface;
132-
+
130+
131+
- class UserResolver implements ResolverInterface
133132
+ class UserQuery implements QueryInterface
133+
{
134+
// ...
135+
}
134136
```

src/Definition/GraphQLServices.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public function query(string $alias, ...$args)
6666
*/
6767
public function mutation(string $alias, ...$args)
6868
{
69+
// TODO: remove the following if-block in 1.0
70+
if (1 === count($args) && is_array($args[0])) {
71+
$args = $args[0];
72+
}
73+
6974
return $this->mutationResolver->resolve([$alias, $args]);
7075
}
7176

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Overblog\GraphQLBundle\Definition\Resolver;
6+
7+
/**
8+
* @deprecated This interface is deprecated since 0.14 and will be removed in 1.0. Use Overblog\GraphQLBundle\Definition\Resolver\QueryInterface instead.
9+
* @codeCoverageIgnore
10+
*/
11+
interface ResolverInterface
12+
{
13+
}

src/DependencyInjection/Compiler/AliasedPass.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
99
use Overblog\GraphQLBundle\Definition\Resolver\MutationInterface;
1010
use Overblog\GraphQLBundle\Definition\Resolver\QueryInterface;
11+
use Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface;
1112
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1213
use Symfony\Component\DependencyInjection\ContainerBuilder;
1314
use Symfony\Component\DependencyInjection\Definition;
@@ -21,6 +22,8 @@ final class AliasedPass implements CompilerPassInterface
2122
MutationInterface::class => 'overblog_graphql.mutation',
2223
QueryInterface::class => 'overblog_graphql.query',
2324
Type::class => TypeTaggedServiceMappingPass::TAG_NAME,
25+
// TODO: remove next line in 1.0
26+
ResolverInterface::class => 'overblog_graphql.resolver',
2427
];
2528

2629
/**
@@ -44,6 +47,16 @@ private function filterDefinitions(array $definitions): array
4447
return array_filter($definitions, function (Definition $definition) {
4548
foreach (self::SERVICE_SUBCLASS_TAG_MAPPING as $tagName) {
4649
if ($definition->hasTag($tagName)) {
50+
// TODO: remove following if-block in 1.0
51+
// @codeCoverageIgnoreStart
52+
if ('overblog_graphql.resolver' === $tagName) {
53+
@trigger_error(
54+
"The 'overblog_graphql.resolver' tag is deprecated since 0.14 and will be removed in 1.0. Use 'overblog_graphql.query' instead. For more info visit: https://github.com/overblog/GraphQLBundle/issues/775",
55+
E_USER_DEPRECATED
56+
);
57+
}
58+
// @codeCoverageIgnoreEnd
59+
4760
return is_subclass_of($definition->getClass(), AliasedInterface::class);
4861
}
4962
}

src/DependencyInjection/Compiler/GraphQLServicesPass.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ final class GraphQLServicesPass implements CompilerPassInterface
2121
public function process(ContainerBuilder $container): void
2222
{
2323
$taggedServices = $container->findTaggedServiceIds('overblog_graphql.service', true);
24+
25+
// TODO: remove following if-block in 1.0
26+
// @codeCoverageIgnoreStart
27+
if (count($deprecatedTaggedServices = $container->findTaggedServiceIds('overblog_graphql.global_variable', true)) > 0) {
28+
@trigger_error(
29+
"The tag 'overblog_graphql.global_variable' is deprecated since 0.14 and will be removed in 1.0. Use 'overblog_graphql.service' instead. For more info visit: https://github.com/overblog/GraphQLBundle/issues/775",
30+
E_USER_DEPRECATED
31+
);
32+
33+
$taggedServices = array_merge($taggedServices, $deprecatedTaggedServices);
34+
}
35+
// @codeCoverageIgnoreEnd
36+
2437
$serviceContainer = ['container' => new Reference('service_container')];
2538
$expressionLanguageDefinition = $container->findDefinition('overblog_graphql.expression_language');
2639

src/DependencyInjection/Compiler/ResolverMethodAliasesPass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
88
use Overblog\GraphQLBundle\Definition\Resolver\MutationInterface;
99
use Overblog\GraphQLBundle\Definition\Resolver\QueryInterface;
10+
use Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface;
1011
use ReflectionClass;
1112
use ReflectionException;
1213
use ReflectionMethod;
@@ -19,6 +20,7 @@ final class ResolverMethodAliasesPass implements CompilerPassInterface
1920
private const SERVICE_SUBCLASS_TAG_MAPPING = [
2021
MutationInterface::class => 'overblog_graphql.mutation',
2122
QueryInterface::class => 'overblog_graphql.query',
23+
ResolverInterface::class => 'overblog_graphql.resolver',
2224
];
2325

2426
/**
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Overblog\GraphQLBundle\DependencyInjection\Compiler;
6+
7+
use InvalidArgumentException;
8+
use function is_string;
9+
use function sprintf;
10+
11+
/**
12+
* TODO: remove this class in 1.0
13+
*
14+
* @deprecated This class is deprecated since 0.14 in favor of QueryTaggedServiceMappingPass and will be removed in 1.0.
15+
* @codeCoverageIgnore
16+
*/
17+
class ResolverTaggedServiceMappingPass extends TaggedServiceMappingPass
18+
{
19+
protected function getTagName(): string
20+
{
21+
return 'overblog_graphql.resolver';
22+
}
23+
24+
protected function checkRequirements(string $id, array $tag): void
25+
{
26+
parent::checkRequirements($id, $tag);
27+
28+
if (isset($tag['method']) && !is_string($tag['method'])) {
29+
throw new InvalidArgumentException(
30+
sprintf('Service tagged "%s" must have valid "method" argument.', $id)
31+
);
32+
}
33+
}
34+
35+
protected function getResolverServiceID(): string
36+
{
37+
return 'overblog_graphql.query_resolver';
38+
}
39+
}

src/ExpressionLanguage/ExpressionFunction/GraphQL/Mutation.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,22 @@ public function __construct($name = self::NAME)
1515
parent::__construct(
1616
$name,
1717
function (string $alias, ...$args) {
18-
$args = count($args) > 0 ? ', '.join(', ', $args) : '';
18+
$count = count($args);
19+
20+
// TODO: remove the following if-else-block in 1.0
21+
if (1 === $count && '$' !== $args[0][0]) {
22+
@trigger_error(
23+
"The signature of the 'mutation' expression function has been changed. Use a variable-length argument list, instead of a signle array argument. For more info visit: https://github.com/overblog/GraphQLBundle/issues/775",
24+
E_USER_DEPRECATED
25+
);
26+
27+
$args = ', '.$args[0];
28+
} else {
29+
$args = $count > 0 ? ', '.join(', ', $args) : '';
30+
}
31+
32+
// TODO: uncomment the following line in 1.0
33+
// $args = $count > 0 ? ', '.join(', ', $args) : '';
1934

2035
return "$this->gqlServices->mutation({$alias}{$args})";
2136
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Overblog\GraphQLBundle\ExpressionLanguage\ExpressionFunction\GraphQL;
6+
7+
use Overblog\GraphQLBundle\ExpressionLanguage\ExpressionFunction;
8+
9+
/**
10+
* @deprecated This class has been deprecated since 0.14 and will be removed in 1.0. Use Overblog\GraphQLBundle\ExpressionLanguage\ExpressionFunction\GraphQL\Query instead.
11+
* @codeCoverageIgnore
12+
*/
13+
final class Resolver extends ExpressionFunction
14+
{
15+
public function __construct($name = 'resolver')
16+
{
17+
parent::__construct(
18+
$name,
19+
function (string $alias, string $args = '[]') {
20+
@trigger_error(
21+
"The expression function 'resolver' has been deprecated since 0.14 and will be removed in 1.0. Use 'query' instead. For more info visit: https://github.com/overblog/GraphQLBundle/issues/775",
22+
E_USER_DEPRECATED
23+
);
24+
25+
return "$this->gqlServices->query($alias, ...$args)";
26+
}
27+
);
28+
}
29+
}

src/OverblogGraphQLBundle.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Overblog\GraphQLBundle\DependencyInjection\Compiler\QueryTaggedServiceMappingPass;
1313
use Overblog\GraphQLBundle\DependencyInjection\Compiler\ResolverMapTaggedServiceMappingPass;
1414
use Overblog\GraphQLBundle\DependencyInjection\Compiler\ResolverMethodAliasesPass;
15+
use Overblog\GraphQLBundle\DependencyInjection\Compiler\ResolverTaggedServiceMappingPass;
1516
use Overblog\GraphQLBundle\DependencyInjection\Compiler\TypeGeneratorPass;
1617
use Overblog\GraphQLBundle\DependencyInjection\Compiler\TypeTaggedServiceMappingPass;
1718
use Overblog\GraphQLBundle\DependencyInjection\OverblogGraphQLExtension;
@@ -47,6 +48,8 @@ public function build(ContainerBuilder $container): void
4748
$container->addCompilerPass(new TypeTaggedServiceMappingPass(), PassConfig::TYPE_BEFORE_REMOVING);
4849
$container->addCompilerPass(new QueryTaggedServiceMappingPass(), PassConfig::TYPE_BEFORE_REMOVING);
4950
$container->addCompilerPass(new MutationTaggedServiceMappingTaggedPass(), PassConfig::TYPE_BEFORE_REMOVING);
51+
// TODO: remove next line in 1.0
52+
$container->addCompilerPass(new ResolverTaggedServiceMappingPass(), PassConfig::TYPE_BEFORE_REMOVING);
5053
}
5154

5255
public function getContainerExtension()

0 commit comments

Comments
 (0)