@@ -581,6 +581,87 @@ public void queryAuthorBooksWithExplictOptionalNotLikeConjunction() {
581
581
assertThat (result .toString ()).isEqualTo (expected );
582
582
}
583
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
+
584
665
@ Test
585
666
public void queryAuthorBooksWithExplictOptionalEXISTS () {
586
667
//given
@@ -620,6 +701,51 @@ public void queryAuthorBooksWithExplictOptionalEXISTS() {
620
701
assertThat (result .toString ()).isEqualTo (expected );
621
702
}
622
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
+
623
749
@ Test
624
750
public void queryAuthorBooksWithCollectionOrderBy () {
625
751
//given
@@ -2169,6 +2295,22 @@ public void ignoreOrder() {
2169
2295
.contains (ErrorType .ValidationError , Arrays .asList ("Books" , "select" , "description" ));
2170
2296
}
2171
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
+
2172
2314
@ Test
2173
2315
public void titleOrder () {
2174
2316
//given
0 commit comments