@escape.tech/graphql-armor-cost-limit
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -9,2 +9,3 @@ import type { Plugin } from '@envelop/core'; | ||
depthCostFactor?: number; | ||
flattenFragments?: boolean; | ||
ignoreIntrospection?: boolean; | ||
@@ -11,0 +12,0 @@ fragmentRecursionCost?: number; |
@@ -1,2 +0,2 @@ | ||
export * from "./declarations/src/index"; | ||
export * from "./declarations/src/index.js"; | ||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ3JhcGhxbC1hcm1vci1jb3N0LWxpbWl0LmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi9kZWNsYXJhdGlvbnMvc3JjL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ== |
@@ -43,2 +43,3 @@ 'use strict'; | ||
depthCostFactor: 1.5, | ||
flattenFragments: false, | ||
fragmentRecursionCost: 1000, | ||
@@ -97,6 +98,9 @@ ignoreIntrospection: true, | ||
for (const child of node.selectionSet.selections) { | ||
cost += this.config.depthCostFactor * this.computeComplexity(child, depth + 1); | ||
if (this.config.flattenFragments && (child.kind === graphql.Kind.INLINE_FRAGMENT || child.kind === graphql.Kind.FRAGMENT_SPREAD)) { | ||
cost += this.computeComplexity(child, depth); | ||
} else { | ||
cost += this.config.depthCostFactor * this.computeComplexity(child, depth + 1); | ||
} | ||
} | ||
} | ||
if (node.kind === graphql.Kind.FRAGMENT_SPREAD) { | ||
} else if (node.kind === graphql.Kind.FRAGMENT_SPREAD) { | ||
if (this.visitedFragments.has(node.name.value)) { | ||
@@ -111,7 +115,13 @@ var _this$visitedFragment; | ||
if (fragment) { | ||
const additionalCost = this.computeComplexity(fragment, depth + 1); | ||
let fragmentCost; | ||
if (this.config.flattenFragments) { | ||
fragmentCost = this.computeComplexity(fragment, depth); | ||
cost += fragmentCost; | ||
} else { | ||
fragmentCost = this.computeComplexity(fragment, depth + 1); | ||
cost += this.config.depthCostFactor * fragmentCost; | ||
} | ||
if (this.visitedFragments.get(node.name.value) === -1) { | ||
this.visitedFragments.set(node.name.value, additionalCost); | ||
this.visitedFragments.set(node.name.value, fragmentCost); | ||
} | ||
cost += this.config.depthCostFactor * additionalCost; | ||
} | ||
@@ -118,0 +128,0 @@ } |
@@ -43,2 +43,3 @@ 'use strict'; | ||
depthCostFactor: 1.5, | ||
flattenFragments: false, | ||
fragmentRecursionCost: 1000, | ||
@@ -97,6 +98,9 @@ ignoreIntrospection: true, | ||
for (const child of node.selectionSet.selections) { | ||
cost += this.config.depthCostFactor * this.computeComplexity(child, depth + 1); | ||
if (this.config.flattenFragments && (child.kind === graphql.Kind.INLINE_FRAGMENT || child.kind === graphql.Kind.FRAGMENT_SPREAD)) { | ||
cost += this.computeComplexity(child, depth); | ||
} else { | ||
cost += this.config.depthCostFactor * this.computeComplexity(child, depth + 1); | ||
} | ||
} | ||
} | ||
if (node.kind === graphql.Kind.FRAGMENT_SPREAD) { | ||
} else if (node.kind === graphql.Kind.FRAGMENT_SPREAD) { | ||
if (this.visitedFragments.has(node.name.value)) { | ||
@@ -111,7 +115,13 @@ var _this$visitedFragment; | ||
if (fragment) { | ||
const additionalCost = this.computeComplexity(fragment, depth + 1); | ||
let fragmentCost; | ||
if (this.config.flattenFragments) { | ||
fragmentCost = this.computeComplexity(fragment, depth); | ||
cost += fragmentCost; | ||
} else { | ||
fragmentCost = this.computeComplexity(fragment, depth + 1); | ||
cost += this.config.depthCostFactor * fragmentCost; | ||
} | ||
if (this.visitedFragments.get(node.name.value) === -1) { | ||
this.visitedFragments.set(node.name.value, additionalCost); | ||
this.visitedFragments.set(node.name.value, fragmentCost); | ||
} | ||
cost += this.config.depthCostFactor * additionalCost; | ||
} | ||
@@ -118,0 +128,0 @@ } |
@@ -39,2 +39,3 @@ import { GraphQLError, Kind } from 'graphql'; | ||
depthCostFactor: 1.5, | ||
flattenFragments: false, | ||
fragmentRecursionCost: 1000, | ||
@@ -93,6 +94,9 @@ ignoreIntrospection: true, | ||
for (const child of node.selectionSet.selections) { | ||
cost += this.config.depthCostFactor * this.computeComplexity(child, depth + 1); | ||
if (this.config.flattenFragments && (child.kind === Kind.INLINE_FRAGMENT || child.kind === Kind.FRAGMENT_SPREAD)) { | ||
cost += this.computeComplexity(child, depth); | ||
} else { | ||
cost += this.config.depthCostFactor * this.computeComplexity(child, depth + 1); | ||
} | ||
} | ||
} | ||
if (node.kind === Kind.FRAGMENT_SPREAD) { | ||
} else if (node.kind === Kind.FRAGMENT_SPREAD) { | ||
if (this.visitedFragments.has(node.name.value)) { | ||
@@ -107,7 +111,13 @@ var _this$visitedFragment; | ||
if (fragment) { | ||
const additionalCost = this.computeComplexity(fragment, depth + 1); | ||
let fragmentCost; | ||
if (this.config.flattenFragments) { | ||
fragmentCost = this.computeComplexity(fragment, depth); | ||
cost += fragmentCost; | ||
} else { | ||
fragmentCost = this.computeComplexity(fragment, depth + 1); | ||
cost += this.config.depthCostFactor * fragmentCost; | ||
} | ||
if (this.visitedFragments.get(node.name.value) === -1) { | ||
this.visitedFragments.set(node.name.value, additionalCost); | ||
this.visitedFragments.set(node.name.value, fragmentCost); | ||
} | ||
cost += this.config.depthCostFactor * additionalCost; | ||
} | ||
@@ -114,0 +124,0 @@ } |
{ | ||
"name": "@escape.tech/graphql-armor-cost-limit", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "Limit the cost of a GraphQL Query.", | ||
@@ -5,0 +5,0 @@ "packageManager": "yarn@4.5.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17564
434