mirror of
https://github.com/swc-project/swc.git
synced 2024-12-20 20:22:26 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
// Loaded from https://deno.land/x/graphql_deno@v15.0.0/lib/validation/rules/UniqueDirectiveNamesRule.js
|
|
|
|
|
|
import { GraphQLError } from '../../error/GraphQLError.js';
|
|
|
|
/**
|
|
* Unique directive names
|
|
*
|
|
* A GraphQL document is only valid if all defined directives have unique names.
|
|
*/
|
|
export function UniqueDirectiveNamesRule(context) {
|
|
const knownDirectiveNames = Object.create(null);
|
|
const schema = context.getSchema();
|
|
return {
|
|
DirectiveDefinition(node) {
|
|
const directiveName = node.name.value;
|
|
|
|
if (schema?.getDirective(directiveName)) {
|
|
context.reportError(new GraphQLError(`Directive "@${directiveName}" already exists in the schema. It cannot be redefined.`, node.name));
|
|
return;
|
|
}
|
|
|
|
if (knownDirectiveNames[directiveName]) {
|
|
context.reportError(new GraphQLError(`There can be only one directive named "@${directiveName}".`, [knownDirectiveNames[directiveName], node.name]));
|
|
} else {
|
|
knownDirectiveNames[directiveName] = node.name;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
};
|
|
} |