Skip to content

Commit

Permalink
test multiple recursion of the same level
Browse files Browse the repository at this point in the history
  • Loading branch information
iamake committed Jun 28, 2018
1 parent a5ea89d commit 2df09da
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/costAnalysis.test.js
Expand Up @@ -48,6 +48,9 @@ const typeDefs = `
second (limit: Int): Second @cost(
multipliers: ["limit"], useMultipliers: true, complexity: ${secondComplexity}
)
anotherSecond (limit: Int): Second @cost(
multipliers: ["limit"], useMultipliers: true, complexity: ${secondComplexity}
)
}
type Second implements BasicInterface {
Expand Down Expand Up @@ -163,6 +166,37 @@ describe('Cost analysis Tests', () => {
expect(visitor.operationMultipliers).toEqual([limit, limit, limit])
})

test('should consider multiple recursive cost computation', () => {
const limit = 10
const ast = parse(`
query {
first(limit: ${limit}) {
second(limit: ${limit}) {
int
}
anotherSecond(limit: ${limit}) {
int
}
}
}
`)

const context = new ValidationContext(schema, ast, typeInfo)
const visitor = new CostAnalysis(context, {
maximumCost: 10000
})

visit(ast, visitWithTypeInfo(typeInfo, visitor))

const firstCost = limit * firstComplexity
const secondCost = limit * limit * secondComplexity
const anotherSecondCost = limit * limit * secondComplexity

const result = firstCost + secondCost + anotherSecondCost
expect(visitor.cost).toEqual(result)
// expect(visitor.operationMultipliers).toEqual([limit, limit])
})

test(`should consider recursive cost computation + empty multipliers array when the node is of kind operation definition`, () => {
const limit = 10
const ast = parse(`
Expand Down

0 comments on commit 2df09da

Please sign in to comment.