graphql-query-complexity
Advanced tools
@@ -69,2 +69,9 @@ "use strict"; | ||
}); | ||
const SDLInterface = new graphql_1.GraphQLInterfaceType({ | ||
name: 'SDLInterface', | ||
fields: { | ||
sdl: { type: graphql_1.GraphQLString } | ||
}, | ||
resolveType: () => '"SDL"' | ||
}); | ||
const Query = new graphql_1.GraphQLObjectType({ | ||
@@ -113,3 +120,4 @@ name: 'Query', | ||
} | ||
} | ||
}, | ||
_service: { type: SDLInterface }, | ||
}), | ||
@@ -116,0 +124,0 @@ }); |
@@ -285,3 +285,40 @@ "use strict"; | ||
}); | ||
it('should return NaN when no astNode available on field when use directiveEstimator', () => { | ||
const ast = graphql_1.parse(` | ||
query { | ||
_service { | ||
sdl | ||
} | ||
} | ||
`); | ||
const complexity = QueryComplexity_1.getComplexity({ | ||
estimators: [ | ||
index_1.directiveEstimator(), | ||
], | ||
schema: schema_1.default, | ||
query: ast | ||
}); | ||
chai_1.expect(Number.isNaN(complexity)).to.equal(true); | ||
}); | ||
it('should skip complexity calculation by directiveEstimator when no astNode available on field', () => { | ||
const ast = graphql_1.parse(` | ||
query { | ||
_service { | ||
sdl | ||
} | ||
} | ||
`); | ||
const complexity = QueryComplexity_1.getComplexity({ | ||
estimators: [ | ||
index_1.directiveEstimator(), | ||
index_1.simpleEstimator({ | ||
defaultComplexity: 1 | ||
}) | ||
], | ||
schema: schema_1.default, | ||
query: ast | ||
}); | ||
chai_1.expect(complexity).to.equal(2); | ||
}); | ||
}); | ||
//# sourceMappingURL=QueryComplexity-test.js.map |
@@ -29,2 +29,6 @@ "use strict"; | ||
return (args) => { | ||
// Ignore if astNode is undefined | ||
if (!args.field.astNode) { | ||
return; | ||
} | ||
const values = graphql_1.getDirectiveValues(directive, args.field.astNode); | ||
@@ -31,0 +35,0 @@ // Ignore if no directive set |
{ | ||
"name": "graphql-query-complexity", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "Validation rule for GraphQL query complexity analysis", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
# GraphQL Query Complexity Analysis for graphql-js | ||
[](https://badge.fury.io/js/graphql-query-complexity) | ||
[](https://circleci.com/gh/slicknode/graphql-query-complexity) | ||
This library provides GraphQL query analysis to reject complex queries to your GraphQL server. | ||
@@ -4,0 +8,0 @@ This can be used to protect your GraphQL servers against resource exhaustion and DoS attacks. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
161825
1.69%2563
1.95%179
2.29%