Skip to content

Commit fb44915

Browse files
captbaritonefacebook-github-bot
authored andcommitted
Repro of weak type resolver GC bug
Differential Revision: D79911205
1 parent 0e81adc commit fb44915

File tree

3 files changed

+259
-0
lines changed

3 files changed

+259
-0
lines changed

packages/relay-runtime/store/__tests__/resolvers/ResolverGC-test.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,82 @@ test('Resolver reading a client-edge to a client type (recursive)', async () =>
827827
});
828828
});
829829

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+
830906
test.each([0, 1, 5])(
831907
'Live Resolver cleanup when %i references retained',
832908
async numRetainedReferences => {

packages/relay-runtime/store/__tests__/resolvers/TodoDescription.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,15 @@ function text_style(
147147
};
148148
}
149149

150+
/**
151+
* @RelayResolver Query.some_todo_description: TodoDescription
152+
*/
153+
function some_todo_description(): TodoDescription {
154+
return {color: 'red', text: 'some todo description'};
155+
}
156+
150157
module.exports = {
158+
some_todo_description,
151159
text_style,
152160
text_with_prefix,
153161
createTodoDescription,

packages/relay-runtime/store/__tests__/resolvers/__generated__/ResolverGCTestWeakQuery.graphql.js

Lines changed: 175 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)