File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -35,11 +35,12 @@ import {
35
35
export class ComplexityPlugin implements ApolloServerPlugin {
36
36
constructor (private gqlSchemaHost : GraphQLSchemaHost ) {}
37
37
38
- requestDidStart(): GraphQLRequestListener {
38
+ async requestDidStart(): Promise <GraphQLRequestListener > {
39
+ const maxComplexity = 20 ;
39
40
const { schema } = this .gqlSchemaHost ;
40
41
41
42
return {
42
- didResolveOperation({ request , document }) {
43
+ async didResolveOperation({ request , document }) {
43
44
const complexity = getComplexity ({
44
45
schema ,
45
46
operationName: request .operationName ,
@@ -50,9 +51,9 @@ export class ComplexityPlugin implements ApolloServerPlugin {
50
51
simpleEstimator ({ defaultComplexity: 1 }),
51
52
],
52
53
});
53
- if (complexity >= 20 ) {
54
+ if (complexity > maxComplexity ) {
54
55
throw new GraphQLError (
55
- ` Query is too complex: ${complexity }. Maximum allowed complexity: 20 ` ,
56
+ ` Query is too complex: ${complexity }. Maximum allowed complexity: ${ maxComplexity } ` ,
56
57
);
57
58
}
58
59
console .log (' Query Complexity:' , complexity );
You can’t perform that action at this time.
0 commit comments