Skip to content

Commit e98203d

Browse files
committed
commented out directives code. not ready launch
1 parent 17f6ec5 commit e98203d

File tree

2 files changed

+33
-35
lines changed

2 files changed

+33
-35
lines changed

src/analysis/ASTParser.ts

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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

test/analysis/typeComplexityAnalysis.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ describe('Test getQueryTypeComplexity function', () => {
855855
});
856856

857857
// TODO: refine complexity analysis to consider directives includes and skip
858-
describe('with directives @includes and @skip', () => {
858+
xdescribe('with directives @includes and @skip', () => {
859859
test('@includes on interfaces', () => {
860860
query = `
861861
query {
@@ -1018,7 +1018,7 @@ describe('Test getQueryTypeComplexity function', () => {
10181018
expect(queryParser.processQuery(parse(query))).toBe(2);
10191019
});
10201020

1021-
test('and other directive are ignored', () => {
1021+
xtest('and other directive are ignored', () => {
10221022
query = `query {
10231023
hero(episode: EMPIRE) {
10241024
id, name

0 commit comments

Comments
 (0)