Search code examples
javaspringgraphql

Is there a way to add bean validation annotations to generated graphql types by graphql-java-codegen?


The situation is that I have my input types and I'd like to validate them. If possible I'd like to use bean validation, but I don't know how to add these annotations to the generated java code by graphql-java-codegen. The validation graphql provides is not sufficient enough, for example it does not have length validation.

The question is that is there a way to add the bean validation annotations to the generated code?

I have the following options:

  1. adding the bean validation annotations somehow to the generated code - this the point of this question

  2. creating my own validators for the generated code which is not a small task. I can't use bean validation here, so I have to write my own validators. It is probably bigger job than maintaining the graphql java side by hand. Or, if I insist to use bean validator I need to map the input to a type I use in the logic and do the validation. But, mapping before validation seems to be a illogical as the validation doesn't happen as early as possible

  3. maintaining the input types (overall the all graphql types java side) by hand. As I mentioned earlier it does not seem to be a big task. So, probably can be a good alternative.

  4. creating my own validation directives. I am not sure I want this.


Solution

  • The generator is capable doing so: here is the answer.