UNPKG

1.49 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const fs = require("fs");
4const schema_1 = require("../hooks/schema");
5const schemaReady_1 = require("../hooks/schemaReady");
6const getTranspiler_1 = require("./getTranspiler");
7const paths_1 = require("../paths");
8const getResolvers_1 = require("./getResolvers");
9const config_1 = require("../config");
10let schema;
11function getSchema() {
12 if (schema !== undefined) {
13 return schema;
14 }
15 const transpiler = getTranspiler_1.getTranspiler();
16 if (process.env.CORTEXQL_COMMAND === 'develop') {
17 // We transpile GraphQL at runtime(ish)
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 // In production we use the generated schema files
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}
39exports.getSchema = getSchema;
40//# sourceMappingURL=getSchema.js.map
\No newline at end of file