Skip to content

Commit

Permalink
feat: cost limit add fragment recursion cost
Browse files Browse the repository at this point in the history
  • Loading branch information
c3b5aw committed Mar 17, 2023
1 parent 330a3a8 commit 0730bb5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tough-weeks-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@escape.tech/graphql-armor-max-aliases': minor
---

add fragmentRecursionCost
4 changes: 3 additions & 1 deletion packages/plugins/cost-limit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ export type CostLimitOptions = {
scalarCost?: number;
depthCostFactor?: number;
ignoreIntrospection?: boolean;
fragmentRecursionCost?: number;
} & GraphQLArmorCallbackConfiguration;
const costLimitDefaultOptions: Required<CostLimitOptions> = {
maxCost: 5000,
objectCost: 2,
scalarCost: 1,
depthCostFactor: 1.5,
fragmentRecursionCost: 1000,
ignoreIntrospection: true,
onAccept: [],
onReject: [],
Expand Down Expand Up @@ -95,7 +97,7 @@ class CostLimitVisitor {

if (node.kind == Kind.FRAGMENT_SPREAD) {
if (this.visitedFragments.has(node.name.value)) {
return 0;
return this.config.fragmentRecursionCost;
}
this.visitedFragments.add(node.name.value);
const fragment = this.context.getFragment(node.name.value);
Expand Down

0 comments on commit 0730bb5

Please sign in to comment.