@@ -827,6 +827,82 @@ test('Resolver reading a client-edge to a client type (recursive)', async () =>
827
827
} ) ;
828
828
} ) ;
829
829
830
+ test ( 'Resolver reading a weak edge' , async ( ) => {
831
+ let calls = 0 ;
832
+ await testResolverGC ( {
833
+ query : graphql `
834
+ query ResolverGCTestWeakQuery {
835
+ some_todo_description {
836
+ text
837
+ }
838
+ }
839
+ ` ,
840
+ variables : { } ,
841
+ payloads : [
842
+ {
843
+ data : { } ,
844
+ } ,
845
+ ] ,
846
+ beforeLookup : recordIdsInStore => {
847
+ expect ( recordIdsInStore ) . toEqual ( [ 'client:root' ] ) ;
848
+ } ,
849
+ afterLookup : ( snapshot , recordIdsInStore ) => {
850
+ expect ( snapshot . data ) . toEqual ( {
851
+ some_todo_description : { text : 'some todo description' } ,
852
+ } ) ;
853
+ expect ( recordIdsInStore ) . toEqual ( [
854
+ 'client:root' ,
855
+ `client:TodoDescription:client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description` ,
856
+ `client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description` ,
857
+ `client:TodoDescription:client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description:$r:text` ,
858
+ ] ) ;
859
+ } ,
860
+ afterRetainedGC : ( snapshot , recordIdsInStore ) => {
861
+ expect ( snapshot . data ) . toEqual ( {
862
+ some_todo_description : { text : 'some todo description' } ,
863
+ } ) ;
864
+
865
+ // TODO: Delete this case once the bug is fixed
866
+ if ( calls === 0 ) {
867
+ // This function gets called twice. Once after GC and again after a second
868
+ // lookup call. After GC this record is missing but after a second lookup it's returned.
869
+ expect ( recordIdsInStore ) . toEqual ( [
870
+ 'client:root' ,
871
+ `client:TodoDescription:client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description` ,
872
+ `client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description` ,
873
+
874
+ // `client:TodoDescription:client:root:${RELAY_READ_TIME_RESOLVER_KEY_PREFIX}some_todo_description:$r:text`,
875
+ ] ) ;
876
+ } else if ( calls === 1 ) {
877
+ expect ( recordIdsInStore ) . toEqual ( [
878
+ 'client:root' ,
879
+ `client:TodoDescription:client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description` ,
880
+ `client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description` ,
881
+ `client:TodoDescription:client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description:$r:text` ,
882
+ ] ) ;
883
+ } else {
884
+ throw new Error ( 'More calls than expected' ) ;
885
+ }
886
+
887
+ calls ++ ;
888
+ } ,
889
+ afterFreedGC : recordIdsInStore => {
890
+ expect ( recordIdsInStore ) . toEqual ( [ 'client:root' ] ) ;
891
+ } ,
892
+ afterLookupAfterFreedGC : ( snapshot , recordIdsInStore ) => {
893
+ expect ( snapshot . data ) . toEqual ( {
894
+ some_todo_description : { text : 'some todo description' } ,
895
+ } ) ;
896
+ expect ( recordIdsInStore ) . toEqual ( [
897
+ 'client:root' ,
898
+ `client:TodoDescription:client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description` ,
899
+ `client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description` ,
900
+ `client:TodoDescription:client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description:$r:text` ,
901
+ ] ) ;
902
+ } ,
903
+ } ) ;
904
+ } ) ;
905
+
830
906
test . each ( [ 0 , 1 , 5 ] ) (
831
907
'Live Resolver cleanup when %i references retained' ,
832
908
async numRetainedReferences => {
0 commit comments