appany / AppAny.HotChocolate.FluentValidation

Input field HotChocolate GraphQL + FluentValidation integration
MIT License
71 stars 16 forks source link

Fluently defined UseFluentValidation doesn't complain when no validation found in Service container #94

Closed falconmick closed 2 years ago

falconmick commented 2 years ago

Describe the bug If I define an argument as having UseFluentValidation I would expect an error if no valid agora found

To Reproduce Add UseFluentValidation to a field which has no validator

Expected behavior An error back from my request letting me know that a validator is missing

Additional context Looking at the source leads me to believe that potentially the solution would be to middlewareContext.ReportError() when we get to line 43 of ValidationMiddleware if InputValidators has a length of 0, however I'm not sure I know enough about the library to tell if this is the correct way to ensure that the validator exists.

For now I am manually wiring up the validator

sergeyshaykhullin commented 2 years ago

@falconmick No. this will not help. This is because you have a default input validator Validators, which calls sp.GetServices() (returning empty array)

Same thing is happening with Validator, but it is using GetRequiredService

I am ok to align this behavior and throw if no validators registered

falconmick commented 2 years ago

Yeah I think throwing of no validation found is just a win win, would suck if bad data got into your system because you accidentally nuked a part of your dependency injection

sergeyshaykhullin commented 2 years ago

Anyway you should cover all system critical parts with tests 😉