Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/type/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,28 @@ function validateDirectives(context: SchemaValidationContext): void {
// TODO: Ensure proper locations.

// Ensure the arguments are valid.
const knownArgNames = Object.create(null);
for (const arg of directive.args) {
// Ensure they are named correctly.
validateName(context, arg);

const argName = arg.name;
// Ensure the type is an input type.
if (!isInputType(arg.type)) {
context.reportError(
`The type of @${directive.name}(${arg.name}:) must be Input Type ` +
`but got: ${inspect(arg.type)}.`,
`The type of @${directive.name}(${argName}:) must be Input Type ` +
`but got: ${inspect(arg.type)}.`,
arg.astNode,
);
}
// Ensure the argument must have a unique name.
if (knownArgNames[argName]) {
context.reportError(
`There can be only one argument named "${argName}".`,
directive.astNode,
);
} else {
knownArgNames[argName] = argName;
}
}
}
}
Expand Down Expand Up @@ -274,6 +284,7 @@ function validateFields(
}

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

Expand All @@ -288,6 +299,16 @@ function validateFields(
arg.astNode?.type,
);
}

// Ensure the argument must have a unique name.
if (knownArgNames[argName]) {
context.reportError(
`There can be only one argument named ${argName}.`,
field.astNode?.type,
);
} else {
knownArgNames[argName] = argName;
}
}
}
}
Expand Down