Skip to content

Commit 5169bb2

Browse files
committed
added test to ensure fragment complexity isn't cached between queries
1 parent ecb8f76 commit 5169bb2

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/analysis/typeComplexityAnalysis.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,50 @@ describe('Test getQueryTypeComplexity function', () => {
359359
// Query 1 + 2*(character 1 + appearsIn/episode 0 + 3 * friends/character 1)
360360
expect(getQueryTypeComplexity(parse(query), variables, typeWeights)).toBe(9);
361361
});
362+
363+
test('recalculates fragment complexity for individual queries', () => {
364+
query = `
365+
query {
366+
leftComparison: hero(episode: EMPIRE) {
367+
...comparisonFields
368+
}
369+
rightComparison: hero(episode: JEDI) {
370+
...comparisonFields
371+
}
372+
}
373+
374+
fragment comparisonFields on Character {
375+
name
376+
appearsIn
377+
friends(first: 3) {
378+
name
379+
}
380+
}`;
381+
mockCharacterFriendsFunction.mockReturnValueOnce(3);
382+
383+
variables = { first: 3 };
384+
// Query 1 + 2*(character 1 + appearsIn/episode 0 + 3 * friends/character 1)
385+
expect(getQueryTypeComplexity(parse(query), variables, typeWeights)).toBe(9);
386+
387+
query = `
388+
query {
389+
leftComparison: hero(episode: EMPIRE) {
390+
...comparisonFields
391+
}
392+
rightComparison: hero(episode: JEDI) {
393+
...comparisonFields
394+
}
395+
}
396+
397+
fragment comparisonFields on Character {
398+
name
399+
appearsIn
400+
}`;
401+
mockCharacterFriendsFunction.mockReturnValueOnce(3);
402+
variables = { first: 3 };
403+
// Query 1 + 2*(character 1 + 0 selectionCost)
404+
expect(getQueryTypeComplexity(parse(query), variables, typeWeights)).toBe(3);
405+
});
362406
});
363407

364408
xdescribe('with inline fragments', () => {

0 commit comments

Comments
 (0)