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 |
---|---|
The AssertFalse Validation Directive is applied to the boolean and checks if it's not false . |
|
The AssertTrue Validation Directive is applied to the boolean and checks if it's not false . |
|
The ContainerNotEmpty Validation Directive is applied to the Lists and Input Objects and checks if it's not null. |
|
The ContainerSize Validation Directive is applied to the Lists , Input Objects and checks if its size is between the specified min and max boundaries. |
|
The DecimalMax Validation Directive is applied to the Float and checks if its value should be less or equal to the specified minimum. |
|
The DecimalMinValidation Directive is applied to the Float and checks if it's more than the specified value. |
|
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. |
|
The Expression Validation Directive is provides an Expression must result to true. |
|
The Max Validation Directive is applied to the Number and checks if it's less than the specified. |
|
The Min Validation Directive is applied to the Number and checks if it's less than specified. |
|
The Negative Validation Directive is applied to the Numbers and checks if it's not negative. |
|
The NegativeOrZero Validation Directive is applied to the Numbers and checks it should be negative or equal to 0. |
|
The NotBlank Validation Directive is applied to the String and checks if it's not blank, it validates according to Java's Character.isWhitespace() . |
|
The NotEmpty Validation Directive is applied to the String and checks if it's not empty. |
|
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. |
|
The Positive Validation Directive is applied to the Numbers and checks if it's not positive. |
|
The PositiveOrZero Validation Directive is applied to the Numbers and checks it should be positive or equal to 0. |
|
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. |