overblog / GraphQLBundle

This bundle provides tools to build a complete GraphQL API server in your Symfony App.
MIT License
783 stars 221 forks source link

EntityExists validation / id exists in a table #1056

Open drmax24 opened 2 years ago

drmax24 commented 2 years ago

I need to write a validation to check if id is present in a database table. Is it possible to do it right now?

In the above post https://github.com/overblog/GraphQLBundle/issues/453 validation EntityExists was mentioned:

Mutation:
    type: object
    config:
        fields:
            createUser:
                type: "String"
                resolve: "@=mut('createUser', [args, validator])"
                args:
                    groups:
                        type: "[String]"
                    userId:
                        type: Int!
                        validation:
                            - EntityExists: App\Entity\User

If i try the above example I have an error:

Constraint class 'Symfony\Component\Validator\Constraints\EntityExists' doesn't exist.

Here is laravel-graphql code for validation if userId exists in a table

class UpdateUserMutation extends Mutation
{
    protected function rules(array $args = []): array
    {
        return [
            'id' => ['required', 'integer', 'exists:user,id'],
        ];
    }

Any ideas if I can check ids against table/entity via graphql validator?