Skip to content

Commit 198d718

Browse files
committed
type complexity test for nonnull wrappers.
1 parent 8d2b1f3 commit 198d718

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

test/analysis/typeComplexityAnalysis.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { TypeWeightObject, Variables } from '../../src/@types/buildTypeWeights';
1313
droid(id: ID!): Droid
1414
human(id: ID!): Human
1515
scalars: Scalars
16+
nonNull: [Droid!]!
1617
}
1718
1819
enum Episode {
@@ -100,6 +101,7 @@ import { TypeWeightObject, Variables } from '../../src/@types/buildTypeWeights';
100101
const mockWeightFunction = jest.fn();
101102
const mockHumanFriendsFunction = jest.fn();
102103
const mockDroidFriendsFunction = jest.fn();
104+
const nonNullMockWeightFunction = jest.fn();
103105

104106
// this object is created by the schema above for use in all the tests below
105107
const typeWeights: TypeWeightObject = {
@@ -114,6 +116,7 @@ const typeWeights: TypeWeightObject = {
114116
droid: 1,
115117
human: 1,
116118
scalars: 1,
119+
nonNull: nonNullMockWeightFunction,
117120
},
118121
},
119122
episode: {
@@ -295,6 +298,14 @@ describe('Test getQueryTypeComplexity function', () => {
295298
expect(mockWeightFunction.mock.calls[1].length).toBe(1);
296299
});
297300

301+
test('with bounded lists including non-null operators', () => {
302+
query = `query {nonNull(episode: EMPIRE, first: 3) { stars, commentary } }`;
303+
nonNullMockWeightFunction.mockReturnValueOnce(3);
304+
expect(getQueryTypeComplexity(parse(query), {}, typeWeights)).toBe(4); // 1 Query + 3 reviews
305+
expect(nonNullMockWeightFunction.mock.calls.length).toBe(1);
306+
expect(nonNullMockWeightFunction.mock.calls[0].length).toBe(1);
307+
});
308+
298309
xdescribe('with nested lists', () => {
299310
test('and simple nesting', () => {
300311
query = `

0 commit comments

Comments
 (0)