Skip to content

Commit 6ec5b58

Browse files
authored
Feature/support list element validation for all constraints (#48)
* fix schema wiring * refactor validation rules * refactor a little * continue * simplify all constraints * fix constraints * add support for list elements for every type of constraint * test * it works * fix tests * fix stuff * add tests * revert small change * add more tests * fix all * update * update readme with new constraints * final reade update * Delete AbstractListElementValidatorConstraint.java * revert readme change
1 parent 6ffc674 commit 6ec5b58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+676
-631
lines changed

README.md

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ The boolean value must be false.
261261

262262
- Example : `updateDriver( isDrunk : Boolean @AssertFalse) : DriverDetails`
263263

264-
- Applies to : `Boolean`
264+
- Applies to : `Boolean`, `Lists`
265265

266266
- SDL : `directive @AssertFalse(message : String = "graphql.validation.AssertFalse.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION`
267267

@@ -274,7 +274,7 @@ The boolean value must be true.
274274

275275
- Example : `driveCar( hasLicence : Boolean @AssertTrue) : DriverDetails`
276276

277-
- Applies to : `Boolean`
277+
- Applies to : `Boolean`, `Lists`
278278

279279
- SDL : `directive @AssertTrue(message : String = "graphql.validation.AssertTrue.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION`
280280

@@ -287,7 +287,7 @@ The element must be a number whose value must be less than or equal to the speci
287287

288288
- Example : `driveCar( bloodAlcoholLevel : Float @DecimalMax(value : "0.05") : DriverDetails`
289289

290-
- Applies to : `String`, `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`
290+
- Applies to : `String`, `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`, `Lists`
291291

292292
- SDL : `directive @DecimalMax(value : String!, inclusive : Boolean! = true, message : String = "graphql.validation.DecimalMax.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION`
293293

@@ -300,7 +300,7 @@ The element must be a number whose value must be greater than or equal to the sp
300300

301301
- Example : `driveCar( carHorsePower : Float @DecimalMin(value : "300.50") : DriverDetails`
302302

303-
- Applies to : `String`, `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`
303+
- Applies to : `String`, `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`, `Lists`
304304

305305
- SDL : `directive @DecimalMin(value : String!, inclusive : Boolean! = true, message : String = "graphql.validation.DecimalMin.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION`
306306

@@ -313,7 +313,7 @@ The element must be a number inside the specified `integer` and `fraction` range
313313

314314
- Example : `buyCar( carCost : Float @Digits(integer : 5, fraction : 2) : DriverDetails`
315315

316-
- Applies to : `String`, `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`
316+
- Applies to : `String`, `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`, `Lists`
317317

318318
- SDL : `directive @Digits(integer : Int!, fraction : Int!, message : String = "graphql.validation.Digits.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION`
319319

@@ -340,7 +340,7 @@ The element must be a number whose value must be less than or equal to the speci
340340

341341
- Example : `driveCar( horsePower : Float @Max(value : 1000) : DriverDetails`
342342

343-
- Applies to : `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`
343+
- Applies to : `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`, `Lists`
344344

345345
- SDL : `directive @Max(value : Int! = 2147483647, message : String = "graphql.validation.Max.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION`
346346

@@ -353,7 +353,7 @@ The element must be a number whose value must be greater than or equal to the sp
353353

354354
- Example : `driveCar( age : Int @Min(value : 18) : DriverDetails`
355355

356-
- Applies to : `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`
356+
- Applies to : `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`, `Lists`
357357

358358
- SDL : `directive @Min(value : Int! = 0, message : String = "graphql.validation.Min.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION`
359359

@@ -366,7 +366,7 @@ The element must be a negative number.
366366

367367
- Example : `driveCar( lostLicencePoints : Int @Negative) : DriverDetails`
368368

369-
- Applies to : `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`
369+
- Applies to : `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`, `Lists`
370370

371371
- SDL : `directive @Negative(message : String = "graphql.validation.Negative.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION`
372372

@@ -379,7 +379,7 @@ The element must be a negative number or zero.
379379

380380
- Example : `driveCar( lostLicencePoints : Int @NegativeOrZero) : DriverDetails`
381381

382-
- Applies to : `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`
382+
- Applies to : `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`, `Lists`
383383

384384
- SDL : `directive @NegativeOrZero(message : String = "graphql.validation.NegativeOrZero.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION`
385385

@@ -401,16 +401,28 @@ The String must contain at least one non-whitespace character, according to Java
401401

402402
### @NotEmpty
403403

404-
The element must have a non zero size.
404+
The element must have a non-zero size.
405405

406-
- Example : `updateAccident( accidentNotes : [Notes]! @NotEmpty) : DriverDetails`
406+
- Example : `updateAccident( accidentNotes : String! @NotEmpty) : DriverDetails`
407407

408-
- Applies to : `String`, `ID`, `Lists`, `Input Objects`
408+
- Applies to : `String`, `ID`, `Lists`
409409

410410
- SDL : `directive @NotEmpty(message : String = "graphql.validation.NotEmpty.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION`
411411

412412
- Message : `graphql.validation.NotEmpty.message`
413413

414+
### @ContainerNotEmpty
415+
416+
The list or input object must have a non-zero size.
417+
418+
- Example : `updateAccident( accidentNotes : [Notes]! @ContainerNotEmpty) : DriverDetails`
419+
420+
- Applies to : `Lists`, `Input Objects`
421+
422+
- SDL : `directive @ContainerNotEmpty(message : String = "graphql.validation.ContainerNotEmpty.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION`
423+
424+
- Message : `graphql.validation.ContainerNotEmpty.message`
425+
414426

415427
### @Pattern
416428

@@ -431,7 +443,7 @@ The element must be a positive number.
431443

432444
- Example : `driver( licencePoints : Int @Positive) : DriverDetails`
433445

434-
- Applies to : `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`
446+
- Applies to : `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`, `Lists`
435447

436448
- SDL : `directive @Positive(message : String = "graphql.validation.Positive.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION`
437449

@@ -444,7 +456,7 @@ The element must be a positive number or zero.
444456

445457
- Example : `driver( licencePoints : Int @PositiveOrZero) : DriverDetails`
446458

447-
- Applies to : `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`
459+
- Applies to : `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`, `Lists`
448460

449461
- SDL : `directive @PositiveOrZero(message : String = "graphql.validation.PositiveOrZero.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION`
450462

@@ -457,7 +469,7 @@ The element range must be between the specified `min` and `max` boundaries (incl
457469

458470
- Example : `driver( milesTravelled : Int @Range( min : 1000, max : 100000)) : DriverDetails`
459471

460-
- Applies to : `String`, `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`
472+
- Applies to : `String`, `Byte`, `Short`, `Int`, `Long`, `BigDecimal`, `BigInteger`, `Float`, `Lists`
461473

462474
- SDL : `directive @Range(min : Int = 0, max : Int = 2147483647, message : String = "graphql.validation.Range.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION`
463475

@@ -466,14 +478,26 @@ The element range must be between the specified `min` and `max` boundaries (incl
466478

467479
### @Size
468480

469-
The element size must be between the specified `min` and `max` boundaries (inclusive).
481+
The string's size must be between the specified `min` and `max` boundaries (inclusive).
470482

471483
- Example : `updateDrivingNotes( drivingNote : String @Size( min : 1000, max : 100000)) : DriverDetails`
472484

473-
- Applies to : `String`, `ID`, `Lists`, `Input Objects`
485+
- Applies to : `String`, `ID`, `Lists`
474486

475487
- SDL : `directive @Size(min : Int = 0, max : Int = 2147483647, message : String = "graphql.validation.Size.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION`
476488

477489
- Message : `graphql.validation.Size.message`
478490

491+
### @ContainerSize
492+
493+
The list's or input object's size must be between the specified `min` and `max` boundaries (inclusive).
494+
495+
- Example : `updateDrivingNotes( drivingNote : [String!]! @ContainerSize( min : 10, max : 20)) : DriverDetails`
496+
497+
- Applies to : `Lists`, `Input Objects`
498+
499+
- SDL : `directive @ContainerSize(min : Int = 0, max : Int = 2147483647, message : String = "graphql.validation.ContainerSize.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION`
500+
501+
- Message : `graphql.validation.ContainerSize.message`
502+
479503
<!-- end -->

build.gradle

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ plugins {
55
id 'java'
66
id 'groovy'
77
id 'java-library'
8-
id 'maven'
98
id 'maven-publish'
109
id 'signing'
1110
id "io.github.gradle-nexus.publish-plugin" version "1.0.0"
@@ -40,14 +39,14 @@ repositories {
4039

4140

4241
dependencies {
43-
compile "com.graphql-java:graphql-java:17.0"
44-
compile "com.graphql-java:graphql-java-extended-scalars:17.0"
45-
compile "org.hibernate.validator:hibernate-validator:7.0.1.Final"
46-
compile "org.glassfish:jakarta.el:4.0.0"
47-
48-
testCompile 'org.slf4j:slf4j-simple:1.7.31'
49-
testCompile 'org.spockframework:spock-core:1.3-groovy-2.5'
50-
testCompile 'org.codehaus.groovy:groovy-all:2.5.14'
42+
api "com.graphql-java:graphql-java:17.0"
43+
api "com.graphql-java:graphql-java-extended-scalars:17.0"
44+
api "org.hibernate.validator:hibernate-validator:7.0.1.Final"
45+
api "org.glassfish:jakarta.el:4.0.0"
46+
47+
testImplementation 'org.slf4j:slf4j-simple:1.7.31'
48+
testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'
49+
testImplementation 'org.codehaus.groovy:groovy-all:2.5.14'
5150
}
5251

5352
task sourcesJar(type: Jar, dependsOn: classes) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)