1 | import { GraphQLError } from "../../error/GraphQLError.mjs";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export function UniqueDirectiveNamesRule(context) {
|
9 | var knownDirectiveNames = Object.create(null);
|
10 | var schema = context.getSchema();
|
11 | return {
|
12 | DirectiveDefinition: function DirectiveDefinition(node) {
|
13 | var directiveName = node.name.value;
|
14 |
|
15 | if (schema !== null && schema !== void 0 && schema.getDirective(directiveName)) {
|
16 | context.reportError(new GraphQLError("Directive \"@".concat(directiveName, "\" already exists in the schema. It cannot be redefined."), node.name));
|
17 | return;
|
18 | }
|
19 |
|
20 | if (knownDirectiveNames[directiveName]) {
|
21 | context.reportError(new GraphQLError("There can be only one directive named \"@".concat(directiveName, "\"."), [knownDirectiveNames[directiveName], node.name]));
|
22 | } else {
|
23 | knownDirectiveNames[directiveName] = node.name;
|
24 | }
|
25 |
|
26 | return false;
|
27 | }
|
28 | };
|
29 | }
|