11# Extended Validation for graphql-java
22
3- This library provides extended validation for [ graphql-java] ( https://github.com/graphql-java/graphql-java )
3+ This library provides extended validation of fields and field arguments for [ graphql-java] ( https://github.com/graphql-java/graphql-java )
44
55
66# Status
@@ -13,16 +13,14 @@ But the project welcomes all feedback and input on code design and validation re
1313
1414TODO
1515
16- # SDL @Directive validation
16+ # SDL @Directive constraints
1717
18- This library a series of directives that can be applied to field arguments and input type fields which will constrain the values
18+ This library a series of directives that can be applied to field arguments and input type fields which will constrain their allowable values.
1919
2020These names and semantics are inspired from the javax.validation annotations
2121
2222https://javaee.github.io/javaee-spec/javadocs/javax/validation/constraints/package-summary.html
2323
24- ## SDL directives
25-
2624You can add these onto arguments or input types in your graphql SDL.
2725
2826For example
@@ -44,113 +42,215 @@ For example
4442 }
4543```
4644
47- In the example above , we have a `applications ` argument that takes at most 10 applications and within each `Application ` input object
45+ In the example above , we have a `applications ` argument that takes at most 10 applications and within each `Application ` input object ,
4846the `name ` field must be at least 3 characters long and no more than 100 characters long to be considered valid .
4947
5048
51- ## The library supplied directives
49+ ## The supplied constraints
5250
53- ### AssertFalse
51+ ### @ AssertFalse
5452
5553The boolean value must be false .
5654
57- - SDL : `directive @AssertFalse (message : String = "graphql.validation.AssertFalse.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION `
58- - Applies to : `Boolean `
55+ - Example : `driver ( isDrunk : Boolean @AssertFalse) : DriverDetails `
56+
57+ - Applies to : `Boolean `
58+
59+ - SDL : directive @AssertFalse (message : String = "graphql.validation.AssertFalse.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
60+
61+ - Message : `graphql .validation .AssertFalse .message `
62+
5963
60- ### AssertTrue
64+ ### @ AssertTrue
6165
6266The boolean value must be true .
6367
64- - SDL : `directive @AssertTrue (message : String = "graphql.validation.AssertTrue.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION `
65- - Applies to : `Boolean `
68+ - Example : `driver ( hasLicence : Boolean @AssertTrue) : DriverDetails `
69+
70+ - Applies to : `Boolean `
71+
72+ - SDL : directive @AssertTrue (message : String = "graphql.validation.AssertTrue.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
73+
74+ - Message : `graphql .validation .AssertTrue .message `
75+
6676
67- ### DecimalMax
77+ ### @ DecimalMax
6878
6979The element must be a number whose value must be less than or equal to the specified maximum .
7080
71- - SDL : `directive @DecimalMax (value : String!, inclusive : Boolean! = true, message : String = "graphql.validation.DecimalMax.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION `
72- - Applies to : `String `, `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
81+ - Example : `driver ( bloodAlcoholLevel : Float @DecimalMax (value : "0.05" ) : DriverDetails `
7382
74- ### DecimalMin
83+ - Applies to : `String `, `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
84+
85+ - SDL : directive @DecimalMax (value : String!, inclusive : Boolean! = true, message : String = "graphql.validation.DecimalMax.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
86+
87+ - Message : `graphql .validation .DecimalMax .message `
88+
89+
90+ ### @DecimalMin
7591
7692The element must be a number whose value must be greater than or equal to the specified minimum .
7793
78- - SDL : `directive @DecimalMin (value : String!, inclusive : Boolean! = true, message : String = "graphql.validation.DecimalMin.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION `
79- - Applies to : `String `, `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
94+ - Example : `driver ( carHorsePower : Float @DecimalMin (value : "300.50" ) : DriverDetails `
95+
96+ - Applies to : `String `, `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
97+
98+ - SDL : directive @DecimalMin (value : String!, inclusive : Boolean! = true, message : String = "graphql.validation.DecimalMin.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
99+
100+ - Message : `graphql .validation .DecimalMin .message `
101+
80102
81- ### Digits
103+ ### @ Digits
82104
83105The element must be a number inside the specified `integer ` and `fraction ` range .
84106
85- - SDL : `directive @Digits (integer : Int!, fraction : Int!, message : String = "graphql.validation.Digits.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION `
86- - Applies to : `String `, `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
107+ - Example : `driver ( carCost : Float @Digits (integer : 5, fraction : 2) : DriverDetails `
87108
88- ### Max
109+ - Applies to : `String `, `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
110+
111+ - SDL : directive @Digits (integer : Int!, fraction : Int!, message : String = "graphql.validation.Digits.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
112+
113+ - Message : `graphql .validation .Digits .message `
114+
115+
116+ ### @Max
89117
90118The element must be a number whose value must be less than or equal to the specified maximum .
91119
92- - SDL : `directive @Max (value : Int! = 2147483647, message : String = "graphql.validation.Max.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION `
93- - Applies to : `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
120+ - Example : `driver ( horsePower : Float @Max (value : 1000) : DriverDetails `
121+
122+ - Applies to : `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
94123
95- ### Min
124+ - SDL : directive @Max (value : Int! = 2147483647, message : String = "graphql.validation.Max.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
125+
126+ - Message : `graphql .validation .Max .message `
127+
128+
129+ ### @Min
96130
97131The element must be a number whose value must be greater than or equal to the specified minimum .
98132
99- - SDL : `directive @Min (value : Int! = 0, message : String = "graphql.validation.Min.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION `
100- - Applies to : `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
133+ - Example : `driver ( age : Int @Min (value : 18) : DriverDetails `
134+
135+ - Applies to : `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
101136
102- ### Negative
137+ - SDL : directive @Min (value : Int! = 0, message : String = "graphql.validation.Min.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
138+
139+ - Message : `graphql .validation .Min .message `
140+
141+
142+ ### @Negative
103143
104144The element must be a negative number .
105145
106- - SDL : `directive @Negative (message : String = "graphql.validation.Negative.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION `
107- - Applies to : `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
146+ - Example : `driver ( licencePoints : Int @Negative) : DriverDetails `
147+
148+ - Applies to : `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
108149
109- ### NegativeOrZero
150+ - SDL : directive @Negative (message : String = "graphql.validation.Negative.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
151+
152+ - Message : `graphql .validation .Negative .message `
153+
154+
155+ ### @NegativeOrZero
110156
111157The element must be a negative number or zero .
112158
113- - SDL : `directive @NegativeOrZero (message : String = "graphql.validation.NegativeOrZero.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION `
114- - Applies to : `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
159+ - Example : `driver ( licencePoints : Int @NegativeOrZero) : DriverDetails `
160+
161+ - Applies to : `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
115162
116- ### NotBlank
163+ - SDL : directive @NegativeOrZero (message : String = "graphql.validation.NegativeOrZero.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
164+
165+ - Message : `graphql .validation .NegativeOrZero .message `
166+
167+
168+ ### @NotBlank
117169
118170The String must contain at least one non -whitespace character , according to Java 's Character .isWhitespace ().
119171
120- - SDL : `directive @NotBlank (message : String = "graphql.validation.NotBlank.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION `
121- - Applies to : `String `
172+ - Example : `updateAccident ( accidentNotes : String @NotBlank) : DriverDetails `
173+
174+ - Applies to : `String `
175+
176+ - SDL : directive @NotBlank (message : String = "graphql.validation.NotBlank.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
122177
123- ### NotEmpty
178+ - Message : `graphql .validation .NotBlank .message `
179+
180+
181+ ### @NotEmpty
124182
125183The element must have a non zero size .
126184
127- - SDL : `directive @NotEmpty (message : String = "graphql.validation.NotEmpty.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION `
128- - Applies to : `String `, `Lists `, `Input Objects `
185+ - Example : `updateAccident ( accidentNotes : [Notes]! @NotEmpty) : DriverDetails `
186+
187+ - Applies to : `String `, `Lists `, `Input Objects `
188+
189+ - SDL : directive @NotEmpty (message : String = "graphql.validation.NotEmpty.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
129190
130- ### Pattern
191+ - Message : `graphql .validation .NotEmpty .message `
192+
193+
194+ ### @Pattern
131195
132196The String must match the specified regular expression , which follows the Java regular expression conventions .
133197
134- - SDL : `directive @Pattern (pattern : String! =".*" , message : String = "graphql.validation.Pattern.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION `
135- - Applies to : `String `
198+ - Example : `updateDriver ( licencePlate : String @Patttern (regex : "[A-Z][A-Z][A-Z]-[0-9][0-9][0-9]" ) : DriverDetails `
199+
200+ - Applies to : `String `
201+
202+ - SDL : directive @Pattern (regexp : String! =".*" , message : String = "graphql.validation.Pattern.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
136203
137- ### Positive
204+ - Message : `graphql .validation .Pattern .message `
205+
206+
207+ ### @Positive
138208
139209The element must be a positive number .
140210
141- - SDL : `directive @Positive (message : String = "graphql.validation.Positive.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION `
142- - Applies to : `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
211+ - Example : `driver ( licencePoints : Int @Positive) : DriverDetails `
212+
213+ - Applies to : `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
214+
215+ - SDL : directive @Positive (message : String = "graphql.validation.Positive.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
143216
144- ### PositiveOrZero
217+ - Message : `graphql .validation .Positive .message `
218+
219+
220+ ### @PositiveOrZero
145221
146222The element must be a positive number or zero .
147223
148- - SDL : `directive @PositiveOrZero (message : String = "graphql.validation.PositiveOrZero.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION `
149- - Applies to : `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
224+ - Example : `driver ( licencePoints : Int @PositiveOrZero) : DriverDetails `
225+
226+ - Applies to : `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
227+
228+ - SDL : directive @PositiveOrZero (message : String = "graphql.validation.PositiveOrZero.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
229+
230+ - Message : `graphql .validation .PositiveOrZero .message `
231+
232+
233+ ### @Range
234+
235+ The element range must be between the specified `min ` and `max ` boundaries (inclusive). It accepts numbers and strings that represent numerical values .
150236
151- ### Size
237+ - Example : `driver ( milesTravelled : Int @Range ( min : 1000, max : 100000)) : DriverDetails `
238+
239+ - Applies to : `String `, `Byte `, `Short `, `Int `, `Long `, `BigDecimal `, `BigInteger `, `Float `
240+
241+ - SDL : directive @Range (min : Int = 0, max : Int = 2147483647, message : String = "graphql.validation.Range.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
242+
243+ - Message : `graphql .validation .Range .message `
244+
245+
246+ ### @Size
152247
153248The element size must be between the specified `min ` and `max ` boundaries (inclusive).
154249
155- - SDL : `directive @Size (min : Int = 0, max : Int = 2147483647, message : String = "graphql.validation.Size.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION `
156- - Applies to : `String `, `Lists `, `Input Objects `
250+ - Example : `updateDriver ( drivingNote : String @Size ( min : 1000, max : 100000)) : DriverDetails `
251+
252+ - Applies to : `String `, `Lists `, `Input Objects `
253+
254+ - SDL : directive @Size (min : Int = 0, max : Int = 2147483647, message : String = "graphql.validation.Size.message" ) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
255+
256+ - Message : `graphql .validation .Size .message `
0 commit comments