Open muhghazaliakbar opened 2 years ago
I could see extending @validate
like this:
"""
Run validation on a field.
"""
directive @validate(
"""
References functions that receive the `Illuminate\Contracts\Validation\Validator` after validation is completed.
Consists of two parts: a class name and a method name, seperated by an `@` symbol.
If you pass only a class name, the method name defaults to `__invoke`.
"""
after: [String!]
) on FIELD_DEFINITION
If you want to add a pull request to support this feature, consider https://github.com/nuwave/lighthouse/blob/master/CONTRIBUTING.md. Tests should be added to https://github.com/nuwave/lighthouse/blob/master/tests/Integration/Validation/ValidationTest.php.
Maybe something like withValidator also for the Validator classes
Having the withValidator
hook available after the main validation has been completed would be useful for us. We need to run validation on a field that might not have been provided to see whether it should have been or not in the context of other input parameters.
Currently, it seems that if a field hasn't been provided in the request, and it's not marked as required
in the validator, no validation gets run on it at all, including any custom validator classes. The withValidator
hook would allow us to get around this.
I have checked the docs about: https://laravel.com/docs/9.x/validation#after-validation-hook but I think this feature isn't available yet, it would be really good if Lighthouse supported this feature