Skip to content

Commit fdc2b1a

Browse files
committed
Add getComplexity test with variables #16
1 parent 1e7a5ee commit fdc2b1a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/__tests__/QueryComplexity-test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ describe('QueryComplexity analysis', () => {
4040
expect(complexity).to.equal(1);
4141
});
4242

43+
it('should calculate complexity with variables', () => {
44+
const ast = parse(`
45+
query Q($count: Int) {
46+
variableScalar(count: $count)
47+
}
48+
`);
49+
50+
const complexity = getComplexity({
51+
estimators: [
52+
fieldConfigEstimator(),
53+
simpleEstimator({defaultComplexity: 1})
54+
],
55+
schema,
56+
query: ast,
57+
variables: {
58+
count: 5,
59+
},
60+
});
61+
expect(complexity).to.equal(50);
62+
});
63+
4364
it('should not allow negative cost', () => {
4465
const ast = parse(`
4566
query {

0 commit comments

Comments
 (0)