1 | import devAssert from "../jsutils/devAssert.mjs";
|
2 | import { Kind } from "../language/kinds.mjs";
|
3 | import { parse } from "../language/parser.mjs";
|
4 | import { assertValidSDL } from "../validation/validate.mjs";
|
5 | import { GraphQLSchema } from "../type/schema.mjs";
|
6 | import { specifiedDirectives } from "../type/directives.mjs";
|
7 | import { extendSchemaImpl } from "./extendSchema.mjs";
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | export function buildASTSchema(documentAST, options) {
|
26 | documentAST != null && documentAST.kind === Kind.DOCUMENT || devAssert(0, 'Must provide valid Document AST.');
|
27 |
|
28 | if ((options === null || options === void 0 ? void 0 : options.assumeValid) !== true && (options === null || options === void 0 ? void 0 : options.assumeValidSDL) !== true) {
|
29 | assertValidSDL(documentAST);
|
30 | }
|
31 |
|
32 | var emptySchemaConfig = {
|
33 | description: undefined,
|
34 | types: [],
|
35 | directives: [],
|
36 | extensions: undefined,
|
37 | extensionASTNodes: [],
|
38 | assumeValid: false
|
39 | };
|
40 | var config = extendSchemaImpl(emptySchemaConfig, documentAST, options);
|
41 |
|
42 | if (config.astNode == null) {
|
43 | for (var _i2 = 0, _config$types2 = config.types; _i2 < _config$types2.length; _i2++) {
|
44 | var type = _config$types2[_i2];
|
45 |
|
46 | switch (type.name) {
|
47 |
|
48 |
|
49 |
|
50 | case 'Query':
|
51 | config.query = type;
|
52 | break;
|
53 |
|
54 | case 'Mutation':
|
55 | config.mutation = type;
|
56 | break;
|
57 |
|
58 | case 'Subscription':
|
59 | config.subscription = type;
|
60 | break;
|
61 | }
|
62 | }
|
63 | }
|
64 |
|
65 | var directives = config.directives;
|
66 |
|
67 | var _loop = function _loop(_i4) {
|
68 | var stdDirective = specifiedDirectives[_i4];
|
69 |
|
70 | if (directives.every(function (directive) {
|
71 | return directive.name !== stdDirective.name;
|
72 | })) {
|
73 | directives.push(stdDirective);
|
74 | }
|
75 | };
|
76 |
|
77 | for (var _i4 = 0; _i4 < specifiedDirectives.length; _i4++) {
|
78 | _loop(_i4);
|
79 | }
|
80 |
|
81 | return new GraphQLSchema(config);
|
82 | }
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | export function buildSchema(source, options) {
|
89 | var document = parse(source, {
|
90 | noLocation: options === null || options === void 0 ? void 0 : options.noLocation,
|
91 | allowLegacySDLEmptyFields: options === null || options === void 0 ? void 0 : options.allowLegacySDLEmptyFields,
|
92 | allowLegacySDLImplementsInterfaces: options === null || options === void 0 ? void 0 : options.allowLegacySDLImplementsInterfaces,
|
93 | experimentalFragmentVariables: options === null || options === void 0 ? void 0 : options.experimentalFragmentVariables
|
94 | });
|
95 | return buildASTSchema(document, {
|
96 | commentDescriptions: options === null || options === void 0 ? void 0 : options.commentDescriptions,
|
97 | assumeValidSDL: options === null || options === void 0 ? void 0 : options.assumeValidSDL,
|
98 | assumeValid: options === null || options === void 0 ? void 0 : options.assumeValid
|
99 | });
|
100 | }
|