All bean validation annotations (@NotNull, @NotEmpty etc), regardless of groups, currently map into GraphQL non-null types. This occasionally causes problems. It should be made possible to globally toggle what validation groups are active. Annotations without groups should still always apply.
The way to activate a group globally will looks like this:
generator.withTypeMappers((config, mappers) -> mappers.replace(
//Replace the default NonNullMapper and activate groups Group1 and Group2
NonNullMapper.class, __ -> new NonNullMapper(Group1.class, Group2.class)))
A built-in group BeanValidationGroupSupport.GraphQL.class is active by default.
Example:
public class Service {
@GraphQLQuery
@NotNull(groups = GraphQL.class) //The return type will be non-null in GraphQL, but not other contexts
public String nonNull(@NotNull(groups = GraphQL.class) String in) { // Likewise for the parameter type
return in;
}
}
All bean validation annotations (
@NotNull
,@NotEmpty
etc), regardless of groups, currently map into GraphQL non-null types. This occasionally causes problems. It should be made possible to globally toggle what validation groups are active. Annotations without groups should still always apply.The way to activate a group globally will looks like this:
A built-in group
BeanValidationGroupSupport.GraphQL.class
is active by default.Example:
See
NonNullTest.java
for more details.Initial work was done in #471 by @esc-sbarden. This adds some configurability.
Note: This is unfortunately a breaking change as it may result in a schema different than what the previous versions of SPQR had produced.