Skip to content

Commit 6f39add

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

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/type/validate.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,28 @@ 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+
// Ensure the argument must have a unique name.
188+
if (knownArgNames[argName]) {
189+
context.reportError(
190+
`There can be only one argument named "${argName}".`,
191+
directive.astNode,
192+
);
193+
} else {
194+
knownArgNames[argName] = argName;
195+
}
186196
}
187197
}
188198
}
@@ -274,6 +284,7 @@ function validateFields(
274284
}
275285

276286
// Ensure the arguments are valid
287+
const knownArgNames = Object.create(null);
277288
for (const arg of field.args) {
278289
const argName = arg.name;
279290

@@ -288,6 +299,16 @@ function validateFields(
288299
arg.astNode?.type,
289300
);
290301
}
302+
303+
// Ensure the argument must have a unique name.
304+
if (knownArgNames[argName]) {
305+
context.reportError(
306+
`There can be only one argument named ${argName}.`,
307+
field.astNode?.type,
308+
);
309+
} else {
310+
knownArgNames[argName] = argName;
311+
}
291312
}
292313
}
293314
}

0 commit comments

Comments
 (0)