Skip to content

Commit 138b119

Browse files
committed
Add deprecations
1 parent 1f44eef commit 138b119

File tree

8 files changed

+77
-10
lines changed

8 files changed

+77
-10
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 (count($args) === 1 && is_array($args[0])) {
71+
$args = $args[0];
72+
}
73+
6974
return $this->mutationResolver->resolve([$alias, $args]);
7075
}
7176

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
*/
10+
interface ResolverInterface
11+
{
12+
}

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 ($count === 1 && '$' !== $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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
*/
12+
final class Resolver extends ExpressionFunction
13+
{
14+
public function __construct($name = 'resolver')
15+
{
16+
parent::__construct(
17+
$name,
18+
function (string $alias, string $args = '[]') {
19+
trigger_error(
20+
"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",
21+
E_USER_DEPRECATED
22+
);
23+
24+
return "$this->gqlServices->query($alias, ...$args)";
25+
}
26+
);
27+
}
28+
}

src/Resources/config/expression_language_functions.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ services:
2727
expression_function.query_alias:
2828
class: Overblog\GraphQLBundle\ExpressionLanguage\ExpressionFunction\GraphQL\Query
2929
arguments: { $name : 'q' }
30+
31+
# Deprecated. To be removed in 1.0
32+
expression_function.resolver_alias:
33+
class: Overblog\GraphQLBundle\ExpressionLanguage\ExpressionFunction\GraphQL\Query
34+
arguments: { $name : 'res' }

tests/Functional/App/config/validator/mapping/Mutation.types.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Mutation:
1515

1616
simpleValidation:
1717
type: Boolean
18-
resolve: "@=mut('mutation_mock', args, validator)"
18+
resolve: "@=mut('mutation_mock', [args, validator])"
1919
args:
2020
username:
2121
type: String!

tests/Functional/Security/AccessTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function setUp(): void
6767
public function testCustomClassLoaderNotRegister(): void
6868
{
6969
$this->expectException(Error::class);
70-
$this->expectExceptionMessage('Class \'Overblog\GraphQLBundle\Access\__DEFINITIONS__\RootQueryType\' not found');
70+
$this->expectExceptionMessage('Class "Overblog\GraphQLBundle\Access\__DEFINITIONS__\RootQueryType" not found');
7171
spl_autoload_unregister($this->loader);
7272
$this->assertResponse($this->userNameQuery, [], static::ANONYMOUS_USER, 'access');
7373
}

0 commit comments

Comments
 (0)