Skip to content

Commit e8ccdf9

Browse files
committed
check duplicate argument define in directive and type
1 parent 7b32413 commit e8ccdf9

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/type/validate.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,27 @@ function validateDirectives(context: SchemaValidationContext): void {
171171
// TODO: Ensure proper locations.
172172

173173
// Ensure the arguments are valid.
174+
const knownArgNames = Object.create(null);
174175
for (const arg of directive.args) {
175176
// Ensure they are named correctly.
176177
validateName(context, arg);
177-
178+
const argName = arg.name;
178179
// Ensure the type is an input type.
179180
if (!isInputType(arg.type)) {
180181
context.reportError(
181-
`The type of @${directive.name}(${arg.name}:) must be Input Type ` +
182-
`but got: ${inspect(arg.type)}.`,
182+
`The type of @${directive.name}(${argName}:) must be Input Type ` +
183+
`but got: ${inspect(arg.type)}.`,
183184
arg.astNode,
184185
);
185186
}
187+
if (knownArgNames[argName]) {
188+
context.reportError(
189+
`There can be only one argument named "${argName}".`,
190+
directive?.astNode,
191+
);
192+
} else {
193+
knownArgNames[argName] = argName;
194+
}
186195
}
187196
}
188197
}
@@ -274,6 +283,7 @@ function validateFields(
274283
}
275284

276285
// Ensure the arguments are valid
286+
const knownArgNames = Object.create(null);
277287
for (const arg of field.args) {
278288
const argName = arg.name;
279289

@@ -288,6 +298,14 @@ function validateFields(
288298
arg.astNode?.type,
289299
);
290300
}
301+
if (knownArgNames[argName]) {
302+
context.reportError(
303+
`There can be only one argument named "${argName}".`,
304+
field.astNode?.type,
305+
);
306+
} else {
307+
knownArgNames[argName] = argName;
308+
}
291309
}
292310
}
293311
}

0 commit comments

Comments
 (0)