Skip to content

Commit 0432986

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

File tree

3 files changed

+265
-0
lines changed

3 files changed

+265
-0
lines changed

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
830912
test.each([0, 1, 5])(
831913
'Live Resolver cleanup when %i references retained',
832914
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)