Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation not working [Update: with Resolver Maps] #1120

Open
ThomasCooks opened this issue May 16, 2023 · 0 comments
Open

Validation not working [Update: with Resolver Maps] #1120

ThomasCooks opened this issue May 16, 2023 · 0 comments

Comments

@ThomasCooks
Copy link

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Version/Branch 0.15.2
Q A
webonyx/graphql-php 14.11.9
Symfony 6.2
PHP 8.2.6

Validation does work in my current GraphQL implementation.

As proposed in the docs I added a validation rule to the first arg of the first field of my root mutation. I also added validation "cascade" to the second arg that is an input object.

See the following example:

RootMutation:
    type: "object"
    config:
        description: RootMutation type
        fieldsDefaultAccess: "@=hasRole('ROLE_USER')"
            updateUser:
                description: Updates a user
                type: "User!"
                access: "@=hasRole('ROLE_USER') && isGranted('user_access', args['id'])"
                args:
                    id:
                        description: ID of the user
                        type: "ID!"
                        validation:
                            - Email: []
                    user:
                        description: Data of the user to update
                        type: "UpdateUser!"
                        validation: cascade

UpdateUser:
    type: "input-object"
    config:
        description: Input object to update a user
        fields:
            displayName:
                description: Display name of the user
                type: "String!"
                validation:
                    - Length:
                          min: 5
                          max: 10

I can see the validation rules are basically processed. When I add a constraint that does not exist, it says:

In TypeBuilder.php line 632:
                                                                               
  Constraint class 'Symfony\Component\Validator\Constraints\WrongEmail' doesn't exist.

I can also see the constraints are added to the auto generated type classes in app/var/cache/test/overblog/graphql-bundle/__definitions__:

final class RootMutationType extends ObjectType implements GeneratedTypeInterface, AliasedInterface
{
    public const NAME = 'RootMutation';
    
    public function __construct(ConfigProcessor $configProcessor, GraphQLServices $services)
    {
        $config = [
            'name' => self::NAME,
            'description' => 'RootMutation type',
            'fields' => fn() => [
                'updateUser' => [
                    'type' => fn() => Type::nonNull($services->getType('User')),
                    'description' => 'Updates a user',
                    'args' => [
                        [
                            'name' => 'id',
                            'type' => Type::nonNull(Type::id()),
                            'description' => 'ID of the user',
                            'validation' => fn() => [
                                new SymfonyConstraints\Email([]),
                            ],
                        ],
...

However, I cannot see the Email validator actually being called. I can put in any value as the user ID. And I cannot see the Length constraint being checked for display name either. Any string value is accepted.

The only thing I get is a deprecation notice:

Remaining indirect deprecation notices (2)

  2x: Creation of dynamic property GraphQL\Type\Definition\InputObjectField::$validation is deprecated
    2x in MutationServiceTest::testUpdatingUser from App\Tests

I tried to debug the the validation process and set break points in different places like in Overblog\GraphQLBundle\Validator\InputValidator, but those lines are never crossed.


Did I miss anything in the docs? Does the validation have to be activated somehow?

Can somebody please confirm this is a bug? Or tell me a good place where to set a debugger breakpoint so I can investigate why validation takes not place in my project?

Thank you!

@ThomasCooks ThomasCooks changed the title Validation not working Validation not working [Update: with Resolver Maps] Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant