1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const fs = require("fs");
|
4 | const schema_1 = require("../hooks/schema");
|
5 | const schemaReady_1 = require("../hooks/schemaReady");
|
6 | const getTranspiler_1 = require("./getTranspiler");
|
7 | const paths_1 = require("../paths");
|
8 | const getResolvers_1 = require("./getResolvers");
|
9 | const config_1 = require("../config");
|
10 | let schema;
|
11 | function getSchema() {
|
12 | if (schema !== undefined) {
|
13 | return schema;
|
14 | }
|
15 | const transpiler = getTranspiler_1.getTranspiler();
|
16 | if (process.env.CORTEXQL_COMMAND === 'develop') {
|
17 |
|
18 | console.log('Generating GraphQL schema...');
|
19 | transpiler.generate();
|
20 | schema = transpiler.getSchema();
|
21 | }
|
22 | else {
|
23 | if (!fs.existsSync(paths_1.getSchemaPath())) {
|
24 | throw new Error('No schema build was found');
|
25 | }
|
26 |
|
27 | console.log('Loading GraphQL schema...');
|
28 | schema = transpiler.restoreSchema(paths_1.getSchemaPath());
|
29 | }
|
30 | const resolvers = getResolvers_1.getResolvers(schema);
|
31 | schema = schema_1.default.filter(schema, { resolvers });
|
32 | transpiler.addResolveFunctionsToSchema(schema, resolvers);
|
33 | if (config_1.config.disableSubscription) {
|
34 | delete schema._subscriptionType;
|
35 | }
|
36 | schemaReady_1.default.do({ schema });
|
37 | return schema;
|
38 | }
|
39 | exports.getSchema = getSchema;
|
40 |
|
\ | No newline at end of file |