lighthouse icon indicating copy to clipboard operation
lighthouse copied to clipboard

Support `after validation hook` Laravel

Open muhghazaliakbar opened this issue 2 years ago • 3 comments

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

muhghazaliakbar avatar Jun 06 '22 13:06 muhghazaliakbar

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.

spawnia avatar Jun 07 '22 07:06 spawnia

Maybe something like withValidator also for the Validator classes

grimxd avatar Jun 08 '22 09:06 grimxd

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.

LarsaSolidor avatar Sep 26 '22 14:09 LarsaSolidor