@@ -827,6 +827,88 @@ test('Resolver reading a client-edge to a client type (recursive)', async () =>
827827 } ) ;
828828} ) ;
829829
830+ test . only ( '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+ // me: {__typename: 'User', id: '1', birthdate: {month: 3, day: 11}},
845+ } ,
846+ } ,
847+ ] ,
848+ beforeLookup : recordIdsInStore => {
849+ expect ( recordIdsInStore ) . toEqual ( [
850+ 'client:root' ,
851+ // '1',
852+ // 'client:1:birthdate',
853+ ] ) ;
854+ } ,
855+ afterLookup : ( snapshot , recordIdsInStore ) => {
856+ expect ( snapshot . data ) . toEqual ( {
857+ some_todo_description : { text : 'some todo description' } ,
858+ } ) ;
859+ expect ( recordIdsInStore ) . toEqual ( [
860+ 'client:root' ,
861+ `client:TodoDescription:client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description` ,
862+ `client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description` ,
863+ `client:TodoDescription:client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description:$r:text` ,
864+ ] ) ;
865+ } ,
866+ afterRetainedGC : ( snapshot , recordIdsInStore ) => {
867+ expect ( snapshot . data ) . toEqual ( {
868+ some_todo_description : { text : 'some todo description' } ,
869+ } ) ;
870+
871+ // TODO: Delete this case once the bug is fixed
872+ if ( calls === 0 ) {
873+ // This function gets called twice. Once after GC and again after a second
874+ // lookup call. After GC this record is missing but after a second lookup it's returned.
875+ expect ( recordIdsInStore ) . toEqual ( [
876+ 'client:root' ,
877+ `client:TodoDescription:client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description` ,
878+ `client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description` ,
879+
880+ // `client:TodoDescription:client:root:${RELAY_READ_TIME_RESOLVER_KEY_PREFIX}some_todo_description:$r:text`,
881+ ] ) ;
882+ } else if ( calls === 1 ) {
883+ expect ( recordIdsInStore ) . toEqual ( [
884+ 'client:root' ,
885+ `client:TodoDescription:client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description` ,
886+ `client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description` ,
887+ `client:TodoDescription:client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description:$r:text` ,
888+ ] ) ;
889+ } else {
890+ throw new Error ( 'More calls than expected' ) ;
891+ }
892+
893+ calls ++ ;
894+ } ,
895+ afterFreedGC : recordIdsInStore => {
896+ expect ( recordIdsInStore ) . toEqual ( [ 'client:root' ] ) ;
897+ } ,
898+ afterLookupAfterFreedGC : ( snapshot , recordIdsInStore ) => {
899+ expect ( snapshot . data ) . toEqual ( {
900+ some_todo_description : { text : 'some todo description' } ,
901+ } ) ;
902+ expect ( recordIdsInStore ) . toEqual ( [
903+ 'client:root' ,
904+ `client:TodoDescription:client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description` ,
905+ `client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description` ,
906+ `client:TodoDescription:client:root:${ RELAY_READ_TIME_RESOLVER_KEY_PREFIX } some_todo_description:$r:text` ,
907+ ] ) ;
908+ } ,
909+ } ) ;
910+ } ) ;
911+
830912test . each ( [ 0 , 1 , 5 ] ) (
831913 'Live Resolver cleanup when %i references retained' ,
832914 async numRetainedReferences => {
0 commit comments