@@ -558,6 +558,10 @@ describe(`NodeModel`, () => {
558
558
{
559
559
id : `id1` ,
560
560
title : `Foo` ,
561
+ nested : {
562
+ foo : `foo1` ,
563
+ bar : `bar1` ,
564
+ } ,
561
565
internal : {
562
566
type : `Test` ,
563
567
contentDigest : `0` ,
@@ -567,6 +571,10 @@ describe(`NodeModel`, () => {
567
571
id : `id2` ,
568
572
title : `Bar` ,
569
573
hidden : false ,
574
+ nested : {
575
+ foo : `foo2` ,
576
+ bar : `bar2` ,
577
+ } ,
570
578
internal : {
571
579
type : `Test` ,
572
580
contentDigest : `1` ,
@@ -582,6 +590,14 @@ describe(`NodeModel`, () => {
582
590
store . dispatch ( {
583
591
type : `CREATE_TYPES` ,
584
592
payload : [
593
+ typeBuilders . buildObjectType ( {
594
+ name : `TestNested` ,
595
+ fields : {
596
+ foo : { type : `String` } ,
597
+ bar : { type : `String` } ,
598
+ } ,
599
+ } ) ,
600
+
585
601
typeBuilders . buildObjectType ( {
586
602
name : `Test` ,
587
603
interfaces : [ `Node` ] ,
@@ -604,6 +620,10 @@ describe(`NodeModel`, () => {
604
620
type : `Boolean!` ,
605
621
resolve : parent => Boolean ( parent . hidden ) ,
606
622
} ,
623
+ nested : {
624
+ type : `TestNested` ,
625
+ resolve : source => source . nested ,
626
+ } ,
607
627
} ,
608
628
} ) ,
609
629
] ,
@@ -702,6 +722,39 @@ describe(`NodeModel`, () => {
702
722
expect ( result [ 0 ] . id ) . toBe ( `id1` )
703
723
expect ( result [ 1 ] . id ) . toBe ( `id2` )
704
724
} )
725
+
726
+ it ( `merges query caches when filtering by nested field` , async ( ) => {
727
+ // See https://github.com/gatsbyjs/gatsby/issues/26056
728
+ nodeModel . replaceFiltersCache ( )
729
+ const result1 = await nodeModel . runQuery (
730
+ {
731
+ query : {
732
+ filter : { nested : { foo : { eq : `foo1` } } } ,
733
+ } ,
734
+ firstOnly : false ,
735
+ type : `Test` ,
736
+ } ,
737
+ { path : `/` }
738
+ )
739
+ const result2 = await nodeModel . runQuery (
740
+ {
741
+ query : {
742
+ filter : { nested : { bar : { eq : `bar2` } } } ,
743
+ } ,
744
+ firstOnly : false ,
745
+ type : `Test` ,
746
+ } ,
747
+ { path : `/` }
748
+ )
749
+
750
+ expect ( result1 ) . toBeTruthy ( )
751
+ expect ( result1 . length ) . toBe ( 1 )
752
+ expect ( result1 [ 0 ] . id ) . toBe ( `id1` )
753
+
754
+ expect ( result2 ) . toBeTruthy ( )
755
+ expect ( result2 . length ) . toBe ( 1 )
756
+ expect ( result2 [ 0 ] . id ) . toBe ( `id2` )
757
+ } )
705
758
} )
706
759
707
760
describe ( `node tracking` , ( ) => {
0 commit comments