how to integrate graphql-java-extended-validation into DGS?
epiphyllum opened this issue · 1 comments
epiphyllum commented
Can dgs be integrated with implementation("com.graphql-java:graphql-java-extended-validation:2022-04-27T05-15-47-b3d9bc3") ?
and how to do it?
implementation("com.graphql-java:graphql-java-extended-validation:2022-04-27T05-15-47-b3d9bc3")
implementation("org.hibernate.validator:hibernate-validator:7.0.4.Final")
type Query {
shows(titleFilter: String @NotBlank): [Show]
}
@DgsComponent
class ValidationConfig {
@DgsRuntimeWiring
fun addValidationDirective(builder: RuntimeWiring.Builder): RuntimeWiring.Builder {
val validationRules = ValidationRules.newValidationRules()
.onValidationErrorStrategy(OnValidationErrorStrategy.RETURN_NULL)
.build()
val wiring = ValidationSchemaWiring(validationRules) // SchemaDirectiveWiring
return builder.directiveWiring(wiring)
}
}
2022-05-22 17:57:10.242 WARN 60792 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dgsQueryExecutor' defined in class path resource [com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'dgsQueryExecutor' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schema' defined in class path resource [com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.GraphQLSchema]: Factory method 'schema' threw exception; nested exception is SchemaProblem{errors=['titleFilter' [@2:11] tried to use an undeclared directive 'NotBlank']}
2022-05-22 17:57:10.244 INFO 60792 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-05-22 17:57:10.254 INFO 60792 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-05-22 17:57:10.271 ERROR 60792 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
There are problems with the GraphQL Schema:
* 'titleFilter' [@2:11] tried to use an undeclared directive 'NotBlank'
springmonster commented
Hi @epiphyllum , you can refer to this commit to see if it is what you want.
springmonster@9b2fa75