Skip to content

Commit dc11004

Browse files
Merge pull request #2048 from Artimunor/master
made example compatible with apollo-server-express v3
2 parents 0817165 + 8bb2a07 commit dc11004

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

content/graphql/complexity.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ import {
3535
export class ComplexityPlugin implements ApolloServerPlugin {
3636
constructor(private gqlSchemaHost: GraphQLSchemaHost) {}
3737

38-
requestDidStart(): GraphQLRequestListener {
38+
async requestDidStart(): Promise<GraphQLRequestListener> {
39+
const maxComplexity = 20;
3940
const { schema } = this.gqlSchemaHost;
4041

4142
return {
42-
didResolveOperation({ request, document }) {
43+
async didResolveOperation({ request, document }) {
4344
const complexity = getComplexity({
4445
schema,
4546
operationName: request.operationName,
@@ -50,9 +51,9 @@ export class ComplexityPlugin implements ApolloServerPlugin {
5051
simpleEstimator({ defaultComplexity: 1 }),
5152
],
5253
});
53-
if (complexity >= 20) {
54+
if (complexity > maxComplexity) {
5455
throw new GraphQLError(
55-
`Query is too complex: ${complexity}. Maximum allowed complexity: 20`,
56+
`Query is too complex: ${complexity}. Maximum allowed complexity: ${maxComplexity}`,
5657
);
5758
}
5859
console.log('Query Complexity:', complexity);

0 commit comments

Comments
 (0)