Skip to content

Commit

Permalink
Add getComplexity test with variables #16
Browse files Browse the repository at this point in the history
  • Loading branch information
ivome committed May 18, 2019
1 parent 1e7a5ee commit fdc2b1a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/__tests__/QueryComplexity-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ describe('QueryComplexity analysis', () => {
expect(complexity).to.equal(1);
});

it('should calculate complexity with variables', () => {
const ast = parse(`
query Q($count: Int) {
variableScalar(count: $count)
}
`);

const complexity = getComplexity({
estimators: [
fieldConfigEstimator(),
simpleEstimator({defaultComplexity: 1})
],
schema,
query: ast,
variables: {
count: 5,
},
});
expect(complexity).to.equal(50);
});

it('should not allow negative cost', () => {
const ast = parse(`
query {
Expand Down

0 comments on commit fdc2b1a

Please sign in to comment.