1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.LoneSchemaDefinitionRule = LoneSchemaDefinitionRule;
|
7 |
|
8 | var _GraphQLError = require("../../error/GraphQLError.js");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | function LoneSchemaDefinitionRule(context) {
|
16 | var _ref, _ref2, _oldSchema$astNode;
|
17 |
|
18 | var oldSchema = context.getSchema();
|
19 | var alreadyDefined = (_ref = (_ref2 = (_oldSchema$astNode = oldSchema === null || oldSchema === void 0 ? void 0 : oldSchema.astNode) !== null && _oldSchema$astNode !== void 0 ? _oldSchema$astNode : oldSchema === null || oldSchema === void 0 ? void 0 : oldSchema.getQueryType()) !== null && _ref2 !== void 0 ? _ref2 : oldSchema === null || oldSchema === void 0 ? void 0 : oldSchema.getMutationType()) !== null && _ref !== void 0 ? _ref : oldSchema === null || oldSchema === void 0 ? void 0 : oldSchema.getSubscriptionType();
|
20 | var schemaDefinitionsCount = 0;
|
21 | return {
|
22 | SchemaDefinition: function SchemaDefinition(node) {
|
23 | if (alreadyDefined) {
|
24 | context.reportError(new _GraphQLError.GraphQLError('Cannot define a new schema within a schema extension.', node));
|
25 | return;
|
26 | }
|
27 |
|
28 | if (schemaDefinitionsCount > 0) {
|
29 | context.reportError(new _GraphQLError.GraphQLError('Must provide only one schema definition.', node));
|
30 | }
|
31 |
|
32 | ++schemaDefinitionsCount;
|
33 | }
|
34 | };
|
35 | }
|