@@ -581,12 +581,18 @@ describe('getCatsByOwner root query', () => {
581
581
cursor = response . body . data . catsConnection . edges [ 0 ] . cursor ;
582
582
} ) ;
583
583
584
- it ( 'brings the correct amount for a segmented query' , async ( ) => {
584
+ it ( 'paginates segmentating by null values' , async ( ) => {
585
+ const [ unnamedCat ] = await catFactory . model . query ( ) . limit ( 1 ) ;
586
+ await catFactory . model . query ( ) . where ( { id : unnamedCat . id } ) . patch ( { lastName : null } ) ;
585
587
const query = `
586
588
{
587
- catsConnection(first: 2, after : "${ cursor } " ) {
589
+ catsConnection(first: 1, orderBy : "lastName", orderDirection: asc ) {
588
590
edges {
589
591
cursor
592
+ node {
593
+ id
594
+ lastName
595
+ }
590
596
}
591
597
totalCount
592
598
}
@@ -595,8 +601,81 @@ describe('getCatsByOwner root query', () => {
595
601
const response = await graphqlQuery ( app , query ) ;
596
602
597
603
expect ( response . body . errors ) . not . toBeDefined ( ) ;
598
- expect ( response . body . data . catsConnection . totalCount ) . toBeDefined ( ) ;
599
- expect ( response . body . data . catsConnection . totalCount ) . toEqual ( 3 ) ;
604
+ // In SQLITE nulls come first.
605
+ expect ( response . body . data . catsConnection . edges [ 0 ] . node . lastName ) . toEqual ( null ) ;
606
+
607
+ const { cursor } = response . body . data . catsConnection . edges [ 0 ] ;
608
+
609
+ const query2 = `
610
+ {
611
+ catsConnection(
612
+ first: 2, orderBy: "lastName", orderDirection: asc, after: "${ cursor } "
613
+ ) {
614
+ edges {
615
+ cursor
616
+ node {
617
+ id
618
+ lastName
619
+ }
620
+ }
621
+ }
622
+ }
623
+ ` ;
624
+ const response2 = await graphqlQuery ( app , query2 ) ;
625
+
626
+ expect ( response2 . body . errors ) . not . toBeDefined ( ) ;
627
+ expect ( response2 . body . data . catsConnection . edges ) . toHaveLength ( 2 ) ;
628
+ expect ( response2 . body . data . catsConnection . edges [ 0 ] . node . lastName ) . not . toEqual ( null ) ;
629
+ expect ( response2 . body . data . catsConnection . edges [ 1 ] . node . lastName ) . not . toEqual ( null ) ;
630
+ } ) ;
631
+
632
+ it ( 'paginates segmentating in the middle of null values' , async ( ) => {
633
+ const [ unnamedCat1 , unnamedCat2 ] = await catFactory . model . query ( ) . limit ( 2 ) ;
634
+ await catFactory . model . query ( ) . where ( { id : unnamedCat1 . id } ) . patch ( { lastName : null } ) ;
635
+ await catFactory . model . query ( ) . where ( { id : unnamedCat2 . id } ) . patch ( { lastName : null } ) ;
636
+ const query = `
637
+ {
638
+ catsConnection(first: 1, orderBy: "lastName", orderDirection: asc) {
639
+ edges {
640
+ cursor
641
+ node {
642
+ id
643
+ lastName
644
+ }
645
+ }
646
+ totalCount
647
+ }
648
+ }
649
+ ` ;
650
+ const response = await graphqlQuery ( app , query ) ;
651
+
652
+ expect ( response . body . errors ) . not . toEqual ( null ) ;
653
+ // In SQLITE nulls come first.
654
+ expect ( response . body . data . catsConnection . edges [ 0 ] . node . lastName ) . toEqual ( null ) ;
655
+
656
+ const { cursor } = response . body . data . catsConnection . edges [ 0 ] ;
657
+
658
+ const query2 = `
659
+ {
660
+ catsConnection(
661
+ first: 2, orderBy: "lastName", orderDirection: asc, after: "${ cursor } "
662
+ ) {
663
+ edges {
664
+ cursor
665
+ node {
666
+ id
667
+ lastName
668
+ }
669
+ }
670
+ }
671
+ }
672
+ ` ;
673
+ const response2 = await graphqlQuery ( app , query2 ) ;
674
+
675
+ expect ( response2 . body . errors ) . not . toEqual ( null ) ;
676
+ expect ( response2 . body . data . catsConnection . edges ) . toHaveLength ( 2 ) ;
677
+ expect ( response2 . body . data . catsConnection . edges [ 0 ] . node . lastName ) . toEqual ( null ) ;
678
+ expect ( response2 . body . data . catsConnection . edges [ 1 ] . node . lastName ) . not . toEqual ( null ) ;
600
679
} ) ;
601
680
} ) ;
602
681
} ) ;
0 commit comments