1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true,
|
5 | });
|
6 | exports.buildASTSchema = buildASTSchema;
|
7 | exports.buildSchema = buildSchema;
|
8 |
|
9 | var _devAssert = require('../jsutils/devAssert.js');
|
10 |
|
11 | var _kinds = require('../language/kinds.js');
|
12 |
|
13 | var _parser = require('../language/parser.js');
|
14 |
|
15 | var _directives = require('../type/directives.js');
|
16 |
|
17 | var _schema = require('../type/schema.js');
|
18 |
|
19 | var _validate = require('../validation/validate.js');
|
20 |
|
21 | var _extendSchema = require('./extendSchema.js');
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | function buildASTSchema(documentAST, options) {
|
34 | (documentAST != null && documentAST.kind === _kinds.Kind.DOCUMENT) ||
|
35 | (0, _devAssert.devAssert)(false, 'Must provide valid Document AST.');
|
36 |
|
37 | if (
|
38 | (options === null || options === void 0 ? void 0 : options.assumeValid) !==
|
39 | true &&
|
40 | (options === null || options === void 0
|
41 | ? void 0
|
42 | : options.assumeValidSDL) !== true
|
43 | ) {
|
44 | (0, _validate.assertValidSDL)(documentAST);
|
45 | }
|
46 |
|
47 | const emptySchemaConfig = {
|
48 | description: undefined,
|
49 | types: [],
|
50 | directives: [],
|
51 | extensions: Object.create(null),
|
52 | extensionASTNodes: [],
|
53 | assumeValid: false,
|
54 | };
|
55 | const config = (0, _extendSchema.extendSchemaImpl)(
|
56 | emptySchemaConfig,
|
57 | documentAST,
|
58 | options,
|
59 | );
|
60 |
|
61 | if (config.astNode == null) {
|
62 | for (const type of config.types) {
|
63 | switch (type.name) {
|
64 |
|
65 |
|
66 |
|
67 | case 'Query':
|
68 |
|
69 | config.query = type;
|
70 | break;
|
71 |
|
72 | case 'Mutation':
|
73 |
|
74 | config.mutation = type;
|
75 | break;
|
76 |
|
77 | case 'Subscription':
|
78 |
|
79 | config.subscription = type;
|
80 | break;
|
81 | }
|
82 | }
|
83 | }
|
84 |
|
85 | const directives = [
|
86 | ...config.directives,
|
87 | ..._directives.specifiedDirectives.filter((stdDirective) =>
|
88 | config.directives.every(
|
89 | (directive) => directive.name !== stdDirective.name,
|
90 | ),
|
91 | ),
|
92 | ];
|
93 | return new _schema.GraphQLSchema({ ...config, directives });
|
94 | }
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | function buildSchema(source, options) {
|
101 | const document = (0, _parser.parse)(source, {
|
102 | noLocation:
|
103 | options === null || options === void 0 ? void 0 : options.noLocation,
|
104 | allowLegacyFragmentVariables:
|
105 | options === null || options === void 0
|
106 | ? void 0
|
107 | : options.allowLegacyFragmentVariables,
|
108 | });
|
109 | return buildASTSchema(document, {
|
110 | assumeValidSDL:
|
111 | options === null || options === void 0 ? void 0 : options.assumeValidSDL,
|
112 | assumeValid:
|
113 | options === null || options === void 0 ? void 0 : options.assumeValid,
|
114 | });
|
115 | }
|