@@ -178,45 +178,43 @@ class ASTParser {
178178 * 2. there is a directive named inlcude and the value is true
179179 * 3. there is a directive named skip and the value is false
180180 */
181- const directive = node . directives ;
182- if ( directive && this . directiveCheck ( directive [ 0 ] ) ) {
183- this . depth += 1 ;
181+ // const directive = node.directives;
182+ // if (directive && this.directiveCheck(directive[0])) {
183+ this . depth += 1 ;
184+ if ( this . depth > this . maxDepth ) this . maxDepth = this . depth ;
185+ // check the kind property against the set of selection nodes that are possible
186+ if ( node . kind === Kind . FIELD ) {
187+ // call the function that handle field nodes
188+ complexity += this . fieldNode ( node , parentName . toLowerCase ( ) ) ;
189+ } else if ( node . kind === Kind . FRAGMENT_SPREAD ) {
190+ // add complexity and depth from fragment cache
191+ const { complexity : fragComplexity , depth : fragDepth } =
192+ this . fragmentCache [ node . name . value ] ;
193+ complexity += fragComplexity ;
194+ this . depth += fragDepth ;
184195 if ( this . depth > this . maxDepth ) this . maxDepth = this . depth ;
185- // check the kind property against the set of selection nodes that are possible
186- if ( node . kind === Kind . FIELD ) {
187- // call the function that handle field nodes
188- complexity += this . fieldNode ( node , parentName . toLowerCase ( ) ) ;
189- } else if ( node . kind === Kind . FRAGMENT_SPREAD ) {
190- // add complexity and depth from fragment cache
191- const { complexity : fragComplexity , depth : fragDepth } =
192- this . fragmentCache [ node . name . value ] ;
193- complexity += fragComplexity ;
194- this . depth += fragDepth ;
195- if ( this . depth > this . maxDepth ) this . maxDepth = this . depth ;
196- this . depth -= fragDepth ;
197-
198- // This is a leaf
199- // need to parse fragment definition at root and get the result here
200- } else if ( node . kind === Kind . INLINE_FRAGMENT ) {
201- const { typeCondition } = node ;
196+ this . depth -= fragDepth ;
202197
203- // named type is the type from which inner fields should be take
204- // If the TypeCondition is omitted, an inline fragment is considered to be of the same type as the enclosing context
205- const namedType = typeCondition
206- ? typeCondition . name . value . toLowerCase ( )
207- : parentName ;
198+ // This is a leaf
199+ // need to parse fragment definition at root and get the result here
200+ } else if ( node . kind === Kind . INLINE_FRAGMENT ) {
201+ const { typeCondition } = node ;
208202
209- // TODO: Handle directives like @include and @skip
210- // subtract 1 before, and add one after, entering the fragment selection to negate the additional level of depth added
211- this . depth -= 1 ;
212- complexity += this . selectionSetNode ( node . selectionSet , namedType ) ;
213- this . depth += 1 ;
214- } else {
215- throw new Error ( `ERROR: ASTParser.selectionNode: node type not supported` ) ;
216- }
203+ // named type is the type from which inner fields should be take
204+ // If the TypeCondition is omitted, an inline fragment is considered to be of the same type as the enclosing context
205+ const namedType = typeCondition ? typeCondition . name . value . toLowerCase ( ) : parentName ;
217206
207+ // TODO: Handle directives like @include and @skip
208+ // subtract 1 before, and add one after, entering the fragment selection to negate the additional level of depth added
218209 this . depth -= 1 ;
210+ complexity += this . selectionSetNode ( node . selectionSet , namedType ) ;
211+ this . depth += 1 ;
212+ } else {
213+ throw new Error ( `ERROR: ASTParser.selectionNode: node type not supported` ) ;
219214 }
215+
216+ this . depth -= 1 ;
217+ // }
220218 return complexity ;
221219 }
222220
0 commit comments