Skip to content

Commit 859ba4d

Browse files
committed
udpated ast parser comments
1 parent 4ba017b commit 859ba4d

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/analysis/ASTnodefunctions.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ class ASTParser {
214214
namedType.toLowerCase()
215215
);
216216

217+
// Don't count fragment complexity in the node's complexity. Only when fragment is used.
217218
this.fragmentCache[fragmentName] = fragmentComplexity;
218-
return complexity; // Don't count complexity here. Only when fragment is used.
219219
} else {
220220
// TODO: Verify that are no other type definition nodes that need to be handled (see ast.d.ts in 'graphql')
221221
// Other types include TypeSystemDefinitionNode (Schema, Type, Directvie) and
@@ -227,14 +227,13 @@ class ASTParser {
227227

228228
documentNode(node: DocumentNode): number {
229229
let complexity = 0;
230-
// iterate through 'definitions' array on the document node
231-
// FIXME: create a copy to preserve original AST order if needed elsewhere
230+
// sort the definitions array by kind so that fragments are always parsed first.
231+
// Fragments must be parsed first so that their complexity is available to other nodes.
232232
const sortedDefinitions = [...node.definitions].sort((a, b) =>
233233
a.kind.localeCompare(b.kind)
234234
);
235235
for (let i = 0; i < sortedDefinitions.length; i += 1) {
236236
// call the function to handle the various types of definition nodes
237-
// FIXME: Need to parse fragment definitions first so that remaining complexity has access to query complexities
238237
complexity += this.definitionNode(sortedDefinitions[i]);
239238
}
240239
return complexity;

0 commit comments

Comments
 (0)