-
Notifications
You must be signed in to change notification settings - Fork 317
integration spring validation #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The existing graphql-java-extended-validation is based on Bean Validation specification, it is easy to add it to Spring GraphQL via ValidationRules validationRules = ValidationRules.newValidationRules()
.onValidationErrorStrategy(OnValidationErrorStrategy.RETURN_NULL)
.build();
//
// This will rewrite your data fetchers when rules apply to them so that validation
ValidationSchemaWiring schemaWiring = new ValidationSchemaWiring(validationRules);
//
// we add this schema wiring to the graphql runtime
builder.directiveWiring(schemaWiring); |
does it work now? i tried last week, crashed graphql-java/graphql-java-extended-validation#51 |
@Diluka yeah, I tried it in the my Dgs example, there is a conflict between the hibernate validators and graphql java verison, Dgs still used 16.x, so I used an older version of Hibernate Validator. Check the configuration here: https://github.com/hantsy/spring-graphql-sample/blob/master/dgs-codegen/src/main/java/com/example/demo/gql/CustomRuntimeWiring.java And declaring a It works as expected. |
@hantsy I have tried. using 16.x will break querydsl integration. |
The example I mentioned above used Netflix Dgs framework which still used GraphQL Java 16.x, not Spring GraphQL. |
Considered under #110 |
@rstoyanchev Should we broaden the scope of #110 or reopen this one? Someone already made the point of directives in #110. |
for most crud like apis, I don't want to create a lot of java dto classes, when graphql can be verified. and repo save method take only entity object not dto. it is not so flexible as it plays in javascript. and querydsl generated apis have no dto classes to use Bean Validation. and maybe mock schema alone |
@Diluka, the Bean Validation annotations can be placed on entity objects. Why separate DTO objects? |
@rstoyanchev DTO is not equal to Entity
there are very like but not the same. for example, two apis have like but different DTO and validation, and process to the same Entity Class object to db. In graphql we use input types and validation directives to filter properties and validate them. and use the same Entity Class in controller method args to receive them and do additional process and save into db. So if the properties are compatible we don't need create additional DTO class and transform them into Entity for saving. And due to the differences we can't use annotations on Entity class. |
bring validation annotations to graphql directives
The text was updated successfully, but these errors were encountered: