UNPKG

@aws-amplify/graphql-transformer-core

Version:

A framework to transform from GraphQL SDL to AWS CloudFormation.

100 lines 4.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UnknownDirectiveError = exports.InvalidDirectiveError = exports.InvalidMigrationError = exports.TransformerContractError = exports.SchemaValidationError = exports.InvalidTransformerError = void 0; const graphql_1 = require("graphql"); const GRAPHQL_TRANSFORMER_V1_DIRECTIVES = ['connection', 'key', 'versioned']; 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 v1DirectivesInUse = new Set(); const newErrors = errors.filter((error) => { if (!error.message.startsWith('Unknown directive')) { return true; } const dir = GRAPHQL_TRANSFORMER_V1_DIRECTIVES.find((d) => error.message.endsWith(`"@${d}".`)); if (!dir) { return true; } v1DirectivesInUse.add(dir); return false; }); if (v1DirectivesInUse.size > 0) { const baseErrorMessage = `Your GraphQL Schema is using ${Array.from(v1DirectivesInUse.values()) .map((d) => `"@${d}"`) .join(', ')} ${v1DirectivesInUse.size > 1 ? 'directives' : 'directive'} from an older 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(baseErrorMessage); } else { super(baseErrorMessage + ` 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 InvalidMigrationError extends Error { constructor(message, causedBy, fix) { super(message); Object.setPrototypeOf(this, InvalidMigrationError.prototype); this.name = 'InvalidMigrationError'; this.fix = fix; this.causedBy = causedBy; } } exports.InvalidMigrationError = InvalidMigrationError; InvalidMigrationError.prototype.toString = function () { return `${this.message}\nCause: ${this.causedBy}\nHow to fix: ${this.fix}`; }; 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; //# sourceMappingURL=index.js.map