Skip to content

Commit 7d362ae

Browse files
committed
1 parent fbb8706 commit 7d362ae

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/GraphQL/helpers/queryComplexity.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { GraphQLError } from 'graphql';
22

3-
function calculateQueryComplexity(document, fragments) {
3+
function calculateQueryComplexity(operation, fragments) {
44
let maxDepth = 0;
55
let totalFields = 0;
66

@@ -35,11 +35,7 @@ function calculateQueryComplexity(document, fragments) {
3535
}
3636
}
3737

38-
for (const definition of document.definitions) {
39-
if (definition.kind === 'OperationDefinition') {
40-
visitSelectionSet(definition.selectionSet, 0, new Set());
41-
}
42-
}
38+
visitSelectionSet(operation.selectionSet, 0, new Set());
4339

4440
return { depth: maxDepth, fields: totalFields };
4541
}
@@ -71,7 +67,7 @@ function createComplexityValidationPlugin(getConfig) {
7167
}
7268

7369
const { depth, fields } = calculateQueryComplexity(
74-
requestContext.document,
70+
requestContext.operation,
7571
fragments
7672
);
7773

0 commit comments

Comments
 (0)