UNPKG

graphql-transformer-core

Version:

A framework to transform from GraphQL SDL to AWS cloudFormation.

164 lines 7.62 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 (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ApiCategorySchemaNotFoundError = exports.UnknownDirectiveError = exports.InvalidDirectiveError = exports.InvalidGSIMigrationError = exports.InvalidMigrationError = exports.DestructiveMigrationError = exports.TransformerContractError = exports.SchemaValidationError = exports.InvalidTransformerError = void 0; const os = __importStar(require("os")); const graphql_1 = require("graphql"); const GRAPHQL_TRANSFORMER_V2_DIRECTIVES = ['hasOne', 'index', 'primaryKey', 'belongsTo', 'manyToMany', 'hasMany', 'default']; class InvalidTransformerError extends Error { constructor(message) { super(message); Object.setPrototypeOf(this, InvalidTransformerError.prototype); this.name = 'InvalidTransformerError'; if (Error.captureStackTrace) { Error.captureStackTrace(this, InvalidTransformerError); } } } exports.InvalidTransformerError = InvalidTransformerError; class SchemaValidationError extends Error { constructor(errors) { const v2DirectivesInUse = new Set(); const newErrors = errors.filter((error) => { if (!error.message.startsWith('Unknown directive')) { return true; } const dir = GRAPHQL_TRANSFORMER_V2_DIRECTIVES.find((d) => error.message.endsWith(`"@${d}".`)); if (!dir) { return true; } v2DirectivesInUse.add(dir); return false; }); if (v2DirectivesInUse.size > 0) { const v2DirectiveErrorMessage = `Your GraphQL Schema is using ${Array.from(v2DirectivesInUse.values()) .map((d) => `"@${d}"`) .join(', ')} ${v2DirectivesInUse.size > 1 ? 'directives' : 'directive'} from the newer version of the GraphQL Transformer. Visit https://docs.amplify.aws/cli/migration/transformer-migration/ to learn how to migrate your GraphQL schema.`; if (newErrors.length === 0) { super(v2DirectiveErrorMessage); } else { super(v2DirectiveErrorMessage + ` There are additional validation errors listed below: \n\n ${newErrors.map((error) => (0, graphql_1.printError)(error)).join('\n\n')}`); } } else { super(`Schema validation failed.\n\n${newErrors.map((error) => (0, graphql_1.printError)(error)).join('\n\n')} `); } Object.setPrototypeOf(this, SchemaValidationError.prototype); this.name = 'SchemaValidationError'; if (Error.captureStackTrace) { Error.captureStackTrace(this, SchemaValidationError); } } } exports.SchemaValidationError = SchemaValidationError; class TransformerContractError extends Error { constructor(message) { super(message); Object.setPrototypeOf(this, TransformerContractError.prototype); this.name = 'TransformerContractError'; if (Error.captureStackTrace) { Error.captureStackTrace(this, TransformerContractError); } } } exports.TransformerContractError = TransformerContractError; class DestructiveMigrationError extends Error { constructor(message, removedModels, replacedModels) { super(message); this.removedModels = removedModels; this.replacedModels = replacedModels; this.toString = () => this.message; Object.setPrototypeOf(this, new.target.prototype); this.name = 'DestructiveMigrationError'; const prependSpace = (str) => ` ${str}`; const removedModelsList = this.removedModels.map(prependSpace).toString().trim(); const replacedModelsList = this.replacedModels.map(prependSpace).toString().trim(); if (removedModelsList && replacedModelsList) { this.message = `${this.message}${os.EOL}This update will remove table(s) [${removedModelsList}] and will replace table(s) [${replacedModelsList}]`; } else if (removedModelsList) { this.message = `${this.message}${os.EOL}This update will remove table(s) [${removedModelsList}]`; } else if (replacedModelsList) { this.message = `${this.message}${os.EOL}This update will replace table(s) [${replacedModelsList}]`; } this.message = `${this.message}${os.EOL}ALL EXISTING DATA IN THESE TABLES WILL BE LOST!${os.EOL}If this is intended, rerun the command with '--allow-destructive-graphql-schema-updates'.`; } } exports.DestructiveMigrationError = DestructiveMigrationError; class InvalidMigrationError extends Error { constructor(message, causedBy, fix) { super(message); this.causedBy = causedBy; this.fix = fix; this.toString = () => `${this.message}\nCause: ${this.causedBy}\nHow to fix: ${this.fix}`; Object.setPrototypeOf(this, new.target.prototype); this.name = 'InvalidMigrationError'; } } exports.InvalidMigrationError = InvalidMigrationError; class InvalidGSIMigrationError extends InvalidMigrationError { constructor(message, causedBy, fix) { super(message, causedBy, fix); this.name = 'InvalidGSIMigrationError'; } } exports.InvalidGSIMigrationError = InvalidGSIMigrationError; class InvalidDirectiveError extends Error { constructor(message) { super(message); Object.setPrototypeOf(this, InvalidDirectiveError.prototype); this.name = 'InvalidDirectiveError'; if (Error.captureStackTrace) { Error.captureStackTrace(this, InvalidDirectiveError); } } } exports.InvalidDirectiveError = InvalidDirectiveError; class UnknownDirectiveError extends Error { constructor(message) { super(message); Object.setPrototypeOf(this, UnknownDirectiveError.prototype); this.name = 'UnknownDirectiveError'; if (Error.captureStackTrace) { Error.captureStackTrace(this, UnknownDirectiveError); } } } exports.UnknownDirectiveError = UnknownDirectiveError; class ApiCategorySchemaNotFoundError extends Error { constructor(schemaFilePath) { super(`Could not find a schema at ${schemaFilePath}`); this.name = 'ApiCategorySchemaNotFoundError'; this.link = 'https://docs.amplify.aws/cli/graphql/overview/#update-schema'; if (Error.captureStackTrace) { Error.captureStackTrace(this, ApiCategorySchemaNotFoundError); } } } exports.ApiCategorySchemaNotFoundError = ApiCategorySchemaNotFoundError; //# sourceMappingURL=errors.js.map