Skip to content

Commit 9e5f06b

Browse files
authored
Ignore size constraint when value is null (#42)
- GraphQL's `!` does this validation by default - This is standard Spring behavior
1 parent 348a51b commit 9e5f06b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main/java/graphql/validation/constraints/standard/SizeConstraint.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@ public boolean appliesToType(GraphQLInputType inputType) {
4545
@Override
4646
protected List<GraphQLError> runConstraint(ValidationEnvironment validationEnvironment) {
4747
Object validatedValue = validationEnvironment.getValidatedValue();
48+
49+
if(validatedValue == null) {
50+
return Collections.emptyList();
51+
}
52+
4853
GraphQLInputType argType = validationEnvironment.getValidatedType();
4954

5055
GraphQLDirective directive = validationEnvironment.getContextObject(GraphQLDirective.class);
5156
int min = getIntArg(directive, "min");
5257
int max = getIntArg(directive, "max");
53-
54-
58+
5559
int size = getStringOrIDOrObjectOrMapLength(argType, validatedValue);
5660

5761
if (size < min) {

0 commit comments

Comments
 (0)