Spring Boot GraphQL Validation with Schema Directive

Input Validation is one of the most important things while inserting or updating existing data. GraphQL allows the Schema Directives to validate the Input Arguments. GraphQL Java team manages an extended validation library that provides basic validation Directives. The Latest version of the extended validation library can be downloaded from here.

Directive Description

AssertFalse

The AssertFalse Validation Directive is applied to the boolean and checks if it's not false.

AssertTrue

The AssertTrue Validation Directive is applied to the boolean and checks if it's not false.

ContainerNotEmpty

The ContainerNotEmpty Validation Directive is applied to the Lists and Input Objects and checks if it's not null.

ContainerSize

The ContainerSize Validation Directive is applied to the Lists, Input Objects and checks if its size is between the specified min and max boundaries.

DecimalMax

The DecimalMax Validation Directive is applied to the Float and checks if its value should be less or equal to the specified minimum.

DecimalMin

The DecimalMinValidation Directive is applied to the Float and checks if it's more than the specified value.

Digits

The Digits Validation Directive is applied to the Float and checks if it's digits before decimal and digits after decimal should be within the specified value.

Expression

The Expression Validation Directive is provides an Expression must result to true.

Max

The Max Validation Directive is applied to the Number and checks if it's less than the specified.

Min

The Min Validation Directive is applied to the Number and checks if it's less than specified.

Negative

The Negative Validation Directive is applied to the Numbers and checks if it's not negative.

NegativeOrZero

The NegativeOrZero Validation Directive is applied to the Numbers and checks it should be negative or equal to 0.

NotBlank

The NotBlank Validation Directive is applied to the String and checks if it's not blank, it validates according to Java's Character.isWhitespace().

NotEmpty

The NotEmpty Validation Directive is applied to the String and checks if it's not empty.

Pattern

The Pattern Validation Directive is applied to the String, ID, Lists and checks The String must match the specified regular expression, it follows the Java regular expression conventions.

Positive

The Positive Validation Directive is applied to the Numbers and checks if it's not positive.

PositiveOrZero

The PositiveOrZero Validation Directive is applied to the Numbers and checks it should be positive or equal to 0.

Range

The Negative Validation Directive is applied to the Numbers and checks if it's not negative.
Size The Size Validation Directive is applied to the String, ID, Lists and checks if its size must be between the specified min and max boundaries.

follow us on