diff --git a/src/Definition/GraphQLServices.php b/src/Definition/GraphQLServices.php index 3633420bb..67b1d8d5a 100644 --- a/src/Definition/GraphQLServices.php +++ b/src/Definition/GraphQLServices.php @@ -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]); diff --git a/src/DependencyInjection/Compiler/AliasedPass.php b/src/DependencyInjection/Compiler/AliasedPass.php index 91ba6347b..45f4d7fe6 100644 --- a/src/DependencyInjection/Compiler/AliasedPass.php +++ b/src/DependencyInjection/Compiler/AliasedPass.php @@ -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); } } diff --git a/src/DependencyInjection/Compiler/GraphQLServicesPass.php b/src/DependencyInjection/Compiler/GraphQLServicesPass.php index f98ac465f..026cc7442 100644 --- a/src/DependencyInjection/Compiler/GraphQLServicesPass.php +++ b/src/DependencyInjection/Compiler/GraphQLServicesPass.php @@ -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", @@ -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'); diff --git a/src/ExpressionLanguage/ExpressionFunction/GraphQL/Resolver.php b/src/ExpressionLanguage/ExpressionFunction/GraphQL/Resolver.php index 18df885d3..78752f15b 100644 --- a/src/ExpressionLanguage/ExpressionFunction/GraphQL/Resolver.php +++ b/src/ExpressionLanguage/ExpressionFunction/GraphQL/Resolver.php @@ -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 { @@ -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 ); diff --git a/src/Validator/Constraints/ExpressionValidator.php b/src/Validator/Constraints/ExpressionValidator.php index f2d256597..7f09a6586 100644 --- a/src/Validator/Constraints/ExpressionValidator.php +++ b/src/Validator/Constraints/ExpressionValidator.php @@ -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'); diff --git a/tests/Functional/App/config/connection/mapping/connection.types.yaml b/tests/Functional/App/config/connection/mapping/connection.types.yaml index ebb1b1db8..3bd5e2a43 100644 --- a/tests/Functional/App/config/connection/mapping/connection.types.yaml +++ b/tests/Functional/App/config/connection/mapping/connection.types.yaml @@ -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 diff --git a/tests/Functional/App/config/connection/services.yml b/tests/Functional/App/config/connection/services.yml index e0498c639..536aaa7fd 100644 --- a/tests/Functional/App/config/connection/services.yml +++ b/tests/Functional/App/config/connection/services.yml @@ -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" } diff --git a/tests/Functional/App/config/node/config.yml b/tests/Functional/App/config/node/config.yml index 4245cb3b4..e14d3b0f1 100644 --- a/tests/Functional/App/config/node/config.yml +++ b/tests/Functional/App/config/node/config.yml @@ -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: diff --git a/tests/Functional/App/config/validator/config.yml b/tests/Functional/App/config/validator/config.yml index b9374e2c0..93cc3f44b 100644 --- a/tests/Functional/App/config/validator/config.yml +++ b/tests/Functional/App/config/validator/config.yml @@ -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: diff --git a/tests/Functional/App/config/validator/mapping/Address.types.yml b/tests/Functional/App/config/validator/mapping/Address.types.yml index 0c437e2a3..3426bd408 100644 --- a/tests/Functional/App/config/validator/mapping/Address.types.yml +++ b/tests/Functional/App/config/validator/mapping/Address.types.yml @@ -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 diff --git a/tests/Functional/App/config/validator/mapping/Mutation.types.yml b/tests/Functional/App/config/validator/mapping/Mutation.types.yml index 043e86eb8..395930db4 100644 --- a/tests/Functional/App/config/validator/mapping/Mutation.types.yml +++ b/tests/Functional/App/config/validator/mapping/Mutation.types.yml @@ -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