Skip to content

Commit

Permalink
Add tests for legacy code
Browse files Browse the repository at this point in the history
* Make all GraphQL services available in the 'expression' constraint
* Remove code coverage suppressions
* Add GraphQLServices::getAll method
  • Loading branch information
murtukov committed Jan 20, 2021
1 parent f8728b9 commit b483a97
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 26 deletions.
8 changes: 8 additions & 0 deletions src/Definition/GraphQLServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public function get(string $name)
return $this->services[$name];
}

/**
* Get all GraphQL services.
*/
public function getAll(): array
{
return $this->services;
}

public function has(string $name): bool
{
return isset($this->services[$name]);
Expand Down
18 changes: 8 additions & 10 deletions src/DependencyInjection/Compiler/AliasedPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,16 @@ public function process(ContainerBuilder $container): void
private function filterDefinitions(array $definitions): array
{
return array_filter($definitions, function (Definition $definition) {
// TODO: remove following if-block in 1.0
if ($definition->hasTag('overblog_graphql.resolver')) {
@trigger_error(
"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",
E_USER_DEPRECATED
);
}

foreach (self::SERVICE_SUBCLASS_TAG_MAPPING as $tagName) {
if ($definition->hasTag($tagName)) {
// TODO: remove following if-block in 1.0
// @codeCoverageIgnoreStart
if ('overblog_graphql.resolver' === $tagName) {
@trigger_error(
"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",
E_USER_DEPRECATED
);
}
// @codeCoverageIgnoreEnd

return is_subclass_of($definition->getClass(), AliasedInterface::class);
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/DependencyInjection/Compiler/GraphQLServicesPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public function process(ContainerBuilder $container): void
$taggedServices = $container->findTaggedServiceIds('overblog_graphql.service', true);

// TODO: remove following if-block in 1.0
// @codeCoverageIgnoreStart
if (count($deprecatedTaggedServices = $container->findTaggedServiceIds('overblog_graphql.global_variable', true)) > 0) {
@trigger_error(
"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",
Expand All @@ -32,7 +31,6 @@ public function process(ContainerBuilder $container): void

$taggedServices = array_merge($taggedServices, $deprecatedTaggedServices);
}
// @codeCoverageIgnoreEnd

$serviceContainer = ['container' => new Reference('service_container')];
$expressionLanguageDefinition = $container->findDefinition('overblog_graphql.expression_language');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
use Overblog\GraphQLBundle\ExpressionLanguage\ExpressionFunction;

/**
* @deprecated This class has been deprecated since 0.14 and will be removed in 1.0. Use Overblog\GraphQLBundle\ExpressionLanguage\ExpressionFunction\GraphQL\Query instead.
* @codeCoverageIgnore
* @deprecated since 0.14 and will be removed in 1.0. Use Overblog\GraphQLBundle\ExpressionLanguage\ExpressionFunction\GraphQL\Query instead.
*/
final class Resolver extends ExpressionFunction
{
Expand All @@ -18,7 +17,7 @@ public function __construct($name = 'resolver')
$name,
function (string $alias, string $args = '[]') {
@trigger_error(
"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",
"The 'resolver' expression function is 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",
E_USER_DEPRECATED
);

Expand Down
3 changes: 3 additions & 0 deletions src/Validator/Constraints/ExpressionValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public function validate($value, Constraint $constraint): void

$variables['this'] = $object;

// Make all tagged GraphQL services available in the expression constraint
$variables = array_merge($variables, $this->graphQLServices->getAll());

if ($object instanceof ValidationNode) {
$variables['parentValue'] = $object->getResolverArg('value');
$variables['context'] = $object->getResolverArg('context');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ User:
friendsForward:
type: userConnection
argsBuilder: "Relay::ForwardConnection"
resolve: '@=query("friends", value, args)'
resolve: '@=resolver("friends", [value, args])'
friendsBackward:
type: userConnection
argsBuilder: "Relay::BackwardConnection"
resolve: '@=query("friends", value, args)'
resolve: '@=resolver("friends", [value, args])'

friendConnection:
type: relay-connection
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/App/config/connection/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
arguments:
- "@overblog_graphql.promise_adapter"
tags:
- { name: "overblog_graphql.query", alias: "friends", method: "friendsResolver" }
- { name: "overblog_graphql.resolver", alias: "friends", method: "friendsResolver" }
- { name: "overblog_graphql.query", alias: "node", method: "resolveNode" }
- { name: "overblog_graphql.query", alias: "query", method: "resolveQuery" }
- { name: "overblog_graphql.query", alias: "connection", method: "resolveConnection" }
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/App/config/node/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ services:
node_resolver:
class: Overblog\GraphQLBundle\Tests\Functional\App\Resolver\NodeResolver
tags:
- { name: "overblog_graphql.query", method: "typeResolver" }
- { name: "overblog_graphql.query", alias: "node_id_fetcher", method: "idFetcher" }
- { name: "overblog_graphql.resolver", method: "typeResolver" }
- { name: "overblog_graphql.resolver", alias: "node_id_fetcher", method: "idFetcher" }
- { name: "overblog_graphql.query", alias: "resolve_photo_field", method: "resolvePhotoField" }

overblog_graphql:
Expand Down
7 changes: 3 additions & 4 deletions tests/Functional/App/config/validator/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ services:
alias: validator.expression

Overblog\GraphQLBundle\Tests\Functional\Validator\ServiceValidator:

service_validator:
alias: Overblog\GraphQLBundle\Tests\Functional\Validator\ServiceValidator
public: true
tags:
# TODO: replace the tag with 'overblog_graphql.service' in 1.0
- { name: overblog_graphql.global_variable, alias: service_validator }

Overblog\GraphQLBundle\Tests\Functional\App\Mutation\InputValidatorMutation:
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Address:
zipCode:
type: Int!
validation:
- Expression: "service('service_validator').isZipCodeValid(value)"
- Expression: "service_validator.isZipCodeValid(value)"
period:
type: Period!
validation: cascade
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Mutation:
username:
type: "String"
validation:
- Expression: "service('service_validator').resolveVariablesAccessible(args, info)"
- Expression: "service_validator.resolveVariablesAccessible(args, info)"

autoValidationAutoThrow:
type: Boolean
Expand Down

0 comments on commit b483a97

Please sign in to comment.