Skip to content

Commit 8f8557b

Browse files
committed
updated the listCost directive to require a positive value
1 parent dd30f63 commit 8f8557b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/analysis/buildTypeWeights.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ function parseObjectFields(
122122
directives.forEach((dir) => {
123123
if (dir.name.value === 'listCost') {
124124
fieldAdded = true;
125-
if (dir.arguments && dir.arguments[0].value.kind === Kind.INT) {
125+
if (
126+
dir.arguments &&
127+
dir.arguments[0].value.kind === Kind.INT &&
128+
Number(dir.arguments[0].value.value) >= 0
129+
) {
126130
result.fields[field] = {
127131
resolveTo: listType.toString().toLocaleLowerCase(),
128132
weight: Number(dir.arguments[0].value.value),
@@ -180,8 +184,8 @@ function parseObjectFields(
180184
}
181185
});
182186

183-
// TODO: check for enforceUnbounded List
184-
// if an unbounded list has no @listCost directive attached
187+
// throw an error if an unbounded list has no @listCost directive attached or slicing arguments
188+
// and the enforceBoundedLists configuration option is sent to true
185189
if (fieldAdded === false && enforceBoundedLists) {
186190
throw new Error(
187191
`ERROR: buildTypeWeights: Use directive @listCost(cost: Int!) on unbounded lists, or limit query results with ${KEYWORDS}`

0 commit comments

Comments
 (0)