graphql-java / graphql-java-extended-validation

Validation library for graphql-java input
MIT License
129 stars 34 forks source link

validation don't work #80

Closed ZeroWM closed 1 year ago

ZeroWM commented 2 years ago
  1. add
    implementation('com.graphql-java:graphql-java-extended-validation:19.0') in the build.gradle
  2. add the code in graphql schema directive @NotBlank(message : String = "graphql.validation.NotBlank.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION

directive @Size(min : Int = 0, max : Int = 2147483647, message : String = "graphql.validation.Size.message")on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION

extend type Mutation { createVirtualGPU(input: CreateVirtualGPUInput): ClusterGPU }

input CreateVirtualGPUInput{ gpuType: GPUType partition: Int = 0 @Size(min : 2, max : 10) count: Int = 0 @Size(min : 1, max : 1000) name: String! @Size(min : 1, max : 100) @NotBlank }

when i tested the code, it doesn't work , don't throw any exception, can you tell me what's the problem in my code?

louis1999 commented 2 years ago

Have you created a config file ? My code wasnt working because of that Here's mine,

@Configuration public class ValidationDirectiveConfig {

@Bean
public RuntimeWiringConfigurer runtimeWiringConfigurer() {

    ValidationRules validationRules = ValidationRules.newValidationRules()
            .onValidationErrorStrategy(OnValidationErrorStrategy.RETURN_NULL)
            .build();

    ValidationSchemaWiring schemaWiring = new ValidationSchemaWiring(validationRules);

    return builder -> builder.directiveWiring(schemaWiring).build();
}

}