Skip to content

Commit 8754486

Browse files
committed
refactored the weight function to have one return statment
1 parent 8f8557b commit 8754486

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/analysis/buildTypeWeights.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ function parseObjectFields(
158158
const weight = isCompositeType(listType)
159159
? typeWeightObject[listType.name.toLowerCase()].weight
160160
: typeWeights.scalar; // Note this includes enums
161+
let multiplier = 1;
161162
if (limitArg) {
162163
const node: ValueNode = limitArg.value;
163-
let multiplier = 1;
164164
if (Kind.INT === node.kind) {
165165
multiplier = Number(node.value || arg.defaultValue);
166166
}
@@ -169,16 +169,13 @@ function parseObjectFields(
169169
variables[node.name.value] || arg.defaultValue
170170
);
171171
}
172-
return multiplier * (selectionsCost + weight);
173172
// ? what else can get through here
174-
}
175-
176-
// if there is no argument provided with the query, check the schema for a default
177-
if (arg.defaultValue) {
178-
return Number(arg.defaultValue) * (selectionsCost + weight);
173+
} else if (arg.defaultValue) {
174+
// if there is no argument provided with the query, check the schema for a default
175+
multiplier = Number(arg.defaultValue);
179176
}
180177
// if there is no argument or default value, return 0 complexity
181-
return 1;
178+
return multiplier * (selectionsCost + weight);
182179
},
183180
};
184181
}

0 commit comments

Comments
 (0)