1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.UniqueTypeNamesRule = UniqueTypeNamesRule;
|
7 |
|
8 | var _GraphQLError = require("../../error/GraphQLError.js");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | function UniqueTypeNamesRule(context) {
|
16 | var knownTypeNames = Object.create(null);
|
17 | var schema = context.getSchema();
|
18 | return {
|
19 | ScalarTypeDefinition: checkTypeName,
|
20 | ObjectTypeDefinition: checkTypeName,
|
21 | InterfaceTypeDefinition: checkTypeName,
|
22 | UnionTypeDefinition: checkTypeName,
|
23 | EnumTypeDefinition: checkTypeName,
|
24 | InputObjectTypeDefinition: checkTypeName
|
25 | };
|
26 |
|
27 | function checkTypeName(node) {
|
28 | var typeName = node.name.value;
|
29 |
|
30 | if (schema !== null && schema !== void 0 && schema.getType(typeName)) {
|
31 | context.reportError(new _GraphQLError.GraphQLError("Type \"".concat(typeName, "\" already exists in the schema. It cannot also be defined in this type definition."), node.name));
|
32 | return;
|
33 | }
|
34 |
|
35 | if (knownTypeNames[typeName]) {
|
36 | context.reportError(new _GraphQLError.GraphQLError("There can be only one type named \"".concat(typeName, "\"."), [knownTypeNames[typeName], node.name]));
|
37 | } else {
|
38 | knownTypeNames[typeName] = node.name;
|
39 | }
|
40 |
|
41 | return false;
|
42 | }
|
43 | }
|