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