UNPKG

@aws-amplify/graphql-schema-generator

Version:
75 lines 3.48 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.graphqlSchemaFromSQLSchema = exports.renderSchema = void 0; const os = __importStar(require("os")); const graphql_transformer_core_1 = require("@aws-amplify/graphql-transformer-core"); const schema_representation_1 = require("./schema-representation"); const schema_generator_1 = require("./schema-generator"); const input_1 = require("./input"); const datasource_adapter_1 = require("./datasource-adapter"); const buildSchemaFromString = (stringSchema, engineType) => { let schema; let adapter; switch (engineType) { case graphql_transformer_core_1.ImportedRDSType.MYSQL: adapter = new datasource_adapter_1.MySQLStringDataSourceAdapter(stringSchema); schema = new schema_representation_1.Schema(new schema_representation_1.Engine('MySQL')); break; case graphql_transformer_core_1.ImportedRDSType.POSTGRESQL: adapter = new datasource_adapter_1.PostgresStringDataSourceAdapter(stringSchema); schema = new schema_representation_1.Schema(new schema_representation_1.Engine('Postgres')); break; default: throw new Error('Only MySQL and Postgres Data Sources are supported'); } const models = adapter.getModels(); models.forEach((m) => schema.addModel(m)); return schema; }; const renderSchema = (schema, databaseConfig, includeAuthRule = false, existingSchema = undefined) => { return (0, input_1.constructRDSGlobalAmplifyInput)(databaseConfig, existingSchema) + os.EOL + os.EOL + (0, schema_generator_1.generateGraphQLSchema)(schema, existingSchema); }; exports.renderSchema = renderSchema; const graphqlSchemaFromSQLSchema = (sqlSchema, engineType) => { const schema = buildSchemaFromString(sqlSchema, engineType); const databaseConfig = { engine: engineType, }; const includeAuthRule = false; return (0, exports.renderSchema)(schema, databaseConfig, includeAuthRule); }; exports.graphqlSchemaFromSQLSchema = graphqlSchemaFromSQLSchema; //# sourceMappingURL=generate.js.map