@@ -393,6 +393,24 @@ public void queryForEnumNe() {
393
393
assertThat (result .toString ()).isEqualTo (expected );
394
394
}
395
395
396
+ @ Test
397
+ public void queryForEnumNotEq () {
398
+ //given
399
+ String query = "{ Books(where: {genre: {NOT: {EQ:PLAY}}}) { select { id title, genre } }}" ;
400
+
401
+ String expected =
402
+ "{Books={select=[" +
403
+ "{id=2, title=War and Peace, genre=NOVEL}, " +
404
+ "{id=3, title=Anna Karenina, genre=NOVEL}" +
405
+ "]}}" ;
406
+
407
+ //when
408
+ Object result = executor .execute (query ).getData ();
409
+
410
+ // then
411
+ assertThat (result .toString ()).isEqualTo (expected );
412
+ }
413
+
396
414
@ Test
397
415
public void queryForEnumNin () {
398
416
//given
@@ -411,6 +429,24 @@ public void queryForEnumNin() {
411
429
assertThat (result .toString ()).isEqualTo (expected );
412
430
}
413
431
432
+ @ Test
433
+ public void queryForEnumNotIn () {
434
+ //given
435
+ String query = "{ Books(where: {genre: {NOT: {IN: PLAY}}}) { select { id title, genre } }}" ;
436
+
437
+ String expected =
438
+ "{Books={select=[" +
439
+ "{id=2, title=War and Peace, genre=NOVEL}, " +
440
+ "{id=3, title=Anna Karenina, genre=NOVEL}" +
441
+ "]}}" ;
442
+
443
+ //when
444
+ Object result = executor .execute (query ).getData ();
445
+
446
+ // then
447
+ assertThat (result .toString ()).isEqualTo (expected );
448
+ }
449
+
414
450
@ Test
415
451
public void queryForParentWithEnum () {
416
452
//given
@@ -467,6 +503,165 @@ public void queryAuthorBooksWithExplictOptional() {
467
503
assertThat (result .toString ()).isEqualTo (expected );
468
504
}
469
505
506
+ @ Test
507
+ public void queryAuthorBooksWithExplictOptionalNotLike () {
508
+ //given
509
+ String query =
510
+ "query { " +
511
+ "Authors(" +
512
+ " where: {" +
513
+ " books: {" +
514
+ " title: {NOT: {LIKE: \" Th\" }}" +
515
+ " }" +
516
+ " }" +
517
+ " ) {" +
518
+ " select {" +
519
+ " id" +
520
+ " name" +
521
+ " books(optional: true) {" +
522
+ " id" +
523
+ " title(orderBy: ASC)" +
524
+ " genre" +
525
+ " }" +
526
+ " }" +
527
+ " }" +
528
+ "}" ;
529
+
530
+ String expected =
531
+ "{Authors={select=[" +
532
+ "{id=1, name=Leo Tolstoy, books=[" +
533
+ "{id=3, title=Anna Karenina, genre=NOVEL}, " +
534
+ "{id=2, title=War and Peace, genre=NOVEL}]}" +
535
+ "]}}" ;
536
+
537
+ //when
538
+ Object result = executor .execute (query ).getData ();
539
+
540
+ // then
541
+ assertThat (result .toString ()).isEqualTo (expected );
542
+ }
543
+
544
+ @ Test
545
+ public void queryAuthorBooksWithExplictOptionalNotLikeConjunction () {
546
+ //given
547
+ String query =
548
+ "query { " +
549
+ "Authors(" +
550
+ " where: {" +
551
+ " books: {" +
552
+ " AND: [{title: {NOT: {LIKE: \" War\" }}} {title: {NOT: {LIKE: \" Anna\" }}}]" +
553
+ " }" +
554
+ " }" +
555
+ " ) {" +
556
+ " select {" +
557
+ " id" +
558
+ " name" +
559
+ " books(optional: true) {" +
560
+ " id" +
561
+ " title(orderBy: ASC)" +
562
+ " genre" +
563
+ " }" +
564
+ " }" +
565
+ " }" +
566
+ "}" ;
567
+
568
+ String expected =
569
+ "{Authors={select=[" +
570
+ "{id=4, name=Anton Chekhov, books=[" +
571
+ "{id=5, title=The Cherry Orchard, genre=PLAY}, " +
572
+ "{id=6, title=The Seagull, genre=PLAY}, " +
573
+ "{id=7, title=Three Sisters, genre=PLAY}" +
574
+ "]}" +
575
+ "]}}" ;
576
+
577
+ //when
578
+ Object result = executor .execute (query ).getData ();
579
+
580
+ // then
581
+ assertThat (result .toString ()).isEqualTo (expected );
582
+ }
583
+
584
+ @ Test
585
+ public void queryAuthorBooksWithNotOutsideOfLikeDisjunction () {
586
+ //should be the same result as queryAuthorBooksWithExplictOptionalNotLikeConjunction above
587
+ //due to logical inversion AND(Not Like A, Not Like B) => NOT(OR(Like a, Like b))
588
+ //given
589
+ String query =
590
+ "query { " +
591
+ "Authors(" +
592
+ " where: {" +
593
+ " books: {" +
594
+ " NOT: {OR: [{title: {LIKE: \" War\" }} {title: {LIKE: \" Anna\" }}]}" +
595
+ " }" +
596
+ " }" +
597
+ " ) {" +
598
+ " select {" +
599
+ " id" +
600
+ " name" +
601
+ " books(optional: true) {" +
602
+ " id" +
603
+ " title(orderBy: ASC)" +
604
+ " genre" +
605
+ " }" +
606
+ " }" +
607
+ " }" +
608
+ "}" ;
609
+
610
+ String expected =
611
+ "{Authors={select=[" +
612
+ "{id=4, name=Anton Chekhov, books=[" +
613
+ "{id=5, title=The Cherry Orchard, genre=PLAY}, " +
614
+ "{id=6, title=The Seagull, genre=PLAY}, " +
615
+ "{id=7, title=Three Sisters, genre=PLAY}" +
616
+ "]}" +
617
+ "]}}" ;
618
+
619
+ //when
620
+ Object result = executor .execute (query ).getData ();
621
+
622
+ // then
623
+ assertThat (result .toString ()).isEqualTo (expected );
624
+ }
625
+
626
+ @ Test
627
+ public void queryAuthorBooksWithNotOutsideOfConjunction () {
628
+ //given
629
+ String query =
630
+ "query { " +
631
+ "Authors(" +
632
+ " where: {" +
633
+ " books: {" +
634
+ " NOT: {AND: [{id: {GE: 4}} {genre: {EQ: PLAY}}]}" +
635
+ " }" +
636
+ " }" +
637
+ " ) {" +
638
+ " select {" +
639
+ " id" +
640
+ " name" +
641
+ " books(optional: true) {" +
642
+ " id" +
643
+ " title(orderBy: ASC)" +
644
+ " genre" +
645
+ " }" +
646
+ " }" +
647
+ " }" +
648
+ "}" ;
649
+
650
+ String expected =
651
+ "{Authors={select=[" +
652
+ "{id=1, name=Leo Tolstoy, books=[" +
653
+ "{id=3, title=Anna Karenina, genre=NOVEL}, " +
654
+ "{id=2, title=War and Peace, genre=NOVEL}" +
655
+ "]}" +
656
+ "]}}" ;
657
+
658
+ //when
659
+ Object result = executor .execute (query ).getData ();
660
+
661
+ // then
662
+ assertThat (result .toString ()).isEqualTo (expected );
663
+ }
664
+
470
665
@ Test
471
666
public void queryAuthorBooksWithExplictOptionalEXISTS () {
472
667
//given
@@ -506,6 +701,51 @@ public void queryAuthorBooksWithExplictOptionalEXISTS() {
506
701
assertThat (result .toString ()).isEqualTo (expected );
507
702
}
508
703
704
+ @ Test
705
+ public void queryAuthorBooksWithExplictOptionalNotEXISTS () {
706
+ //given
707
+ String query =
708
+ "query { " +
709
+ "Authors(" +
710
+ " where: {" +
711
+ " NOT: {" +
712
+ " EXISTS: {" +
713
+ " books: {" +
714
+ " title: {LIKE: \" War\" }" +
715
+ " }" +
716
+ " }" +
717
+ " }" +
718
+ " }" +
719
+ " ) {" +
720
+ " select {" +
721
+ " id" +
722
+ " name" +
723
+ " books(optional: true) {" +
724
+ " id" +
725
+ " title(orderBy: ASC)" +
726
+ " genre" +
727
+ " }" +
728
+ " }" +
729
+ " }" +
730
+ "}" ;
731
+
732
+ String expected =
733
+ "{Authors={select=[" +
734
+ "{id=4, name=Anton Chekhov, books=[" +
735
+ "{id=5, title=The Cherry Orchard, genre=PLAY}," +
736
+ " {id=6, title=The Seagull, genre=PLAY}," +
737
+ " {id=7, title=Three Sisters, genre=PLAY}" +
738
+ "]}, " +
739
+ "{id=8, name=Igor Dianov, books=[]}" +
740
+ "]}}" ;
741
+
742
+ //when
743
+ Object result = executor .execute (query ).getData ();
744
+
745
+ // then
746
+ assertThat (result .toString ()).isEqualTo (expected );
747
+ }
748
+
509
749
@ Test
510
750
public void queryAuthorBooksWithCollectionOrderBy () {
511
751
//given
@@ -2055,6 +2295,22 @@ public void ignoreOrder() {
2055
2295
.contains (ErrorType .ValidationError , Arrays .asList ("Books" , "select" , "description" ));
2056
2296
}
2057
2297
2298
+ @ Test
2299
+ public void logicalNotOnlySupportsSingleOperand () {
2300
+ //given
2301
+ String query = "{ Books(where: {NOT: [{id: {EQ: 1}} {id: {EQ: 2}}]}){ select { id description } }}" ;
2302
+
2303
+ List <GraphQLError > result = executor .execute (query ).getErrors ();
2304
+
2305
+ //then
2306
+ assertThat (result ).hasSize (1 );
2307
+ assertThat (result .get (0 ))
2308
+ .isExactlyInstanceOf (ValidationError .class )
2309
+ .extracting (ValidationError .class ::cast )
2310
+ .extracting ("errorType" , "queryPath" )
2311
+ .contains (ErrorType .ValidationError , Arrays .asList ("Books" ));
2312
+ }
2313
+
2058
2314
@ Test
2059
2315
public void titleOrder () {
2060
2316
//given
0 commit comments