UNPKG

@aws-amplify/graphql-transformer-core

Version:

A framework to transform from GraphQL SDL to AWS CloudFormation.

45 lines 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TransformerSchema = void 0; const aws_appsync_1 = require("aws-cdk-lib/aws-appsync"); const aws_cdk_lib_1 = require("aws-cdk-lib"); const utils_1 = require("../transformation/utils"); class TransformerSchema { constructor() { this.definition = ''; this.bind = (api) => { if (!this.schemaConstruct) { const schema = this; this.api = api; this.schemaConstruct = new aws_appsync_1.CfnGraphQLSchema(api, 'TransformerSchema', { apiId: api.apiId, definitionS3Location: aws_cdk_lib_1.Lazy.string({ produce: () => { const asset = schema.addAsset(); return asset.s3ObjectUrl; }, }), }); } return this.schemaConstruct; }; this.addAsset = () => { if (!this.api) { throw new Error('Schema not bound'); } if (!this.asset) { this.asset = this.api.assetProvider.provide(this.api, 'schema', { fileName: 'schema.graphql', fileContent: (0, utils_1.removeAmplifyInputDefinition)(this.definition), }); } return this.asset; }; this.addToSchema = (addition, delimiter) => { const sep = delimiter !== null && delimiter !== void 0 ? delimiter : ''; this.definition = `${this.definition}${sep}${addition}\n`; }; } } exports.TransformerSchema = TransformerSchema; //# sourceMappingURL=schema-asset.js.map