Deploy an AppSync API with a schema definition file and resolver mapping templates in a CodePipeline using CloudFormation actions.
Use Case
I want to deploy an AppSync API in a CodePipeline and I don't want to inline the schema into the CDK code because I want to generate model classes from it.
Currently, the schema definition must be provided either as a string or as an asset (not yet supported by CloudFormations actions).
It is not possible to provide S3-locations without redefining the current L2-construct.
CDK source code:
|
let definition; |
|
if (props.schemaDefinition) { |
|
definition = props.schemaDefinition; |
|
} else if (props.schemaDefinitionFile) { |
|
definition = readFileSync(props.schemaDefinitionFile).toString('UTF-8'); |
|
} else { |
|
throw new Error('Missing Schema definition. Provide schemaDefinition or schemaDefinitionFile'); |
|
} |
Proposed Solution
Provide S3-locations of the schema definition file and any resolver mapping templates to the synthesized template using CloudFormation parameters, similar to CfnParametersCode (see example here).
Since the number of mapping templates can be very high, a solution that requires only one parameter representing the S3-folder containing the mapping templates would be useful.
Creating an AppSync API and mapping templates could look like:
const schema = new cdk.CfnParameter(this, 'GraphQLSchemaS3Location');
const resolversDir = new cdk.CfnParameter(this, 'GraphQLMappingTemplatesS3Location');
const api = new appsync.GraphQLApi(this, 'GraphQLApi', {
name: `GraphQLApi`,
schemaDefinitionLocation: schema,
});
someDataSource.createQueryResolver({
field: 'getHello',
requestTemplate: appsync.MappingTemplate.fromS3Location(resolversDir, 'getHello-request-mapping-template.vtl'),
responseTemplate: appsync.MappingTemplate.fromS3Location(resolversDir, 'getHello-response-mapping-template.vtl'),
});
Other
Related question on Gitter.
This is a 🚀 Feature Request
Deploy an AppSync API with a schema definition file and resolver mapping templates in a CodePipeline using CloudFormation actions.
Use Case
I want to deploy an AppSync API in a CodePipeline and I don't want to inline the schema into the CDK code because I want to generate model classes from it.
Currently, the schema definition must be provided either as a string or as an asset (not yet supported by CloudFormations actions).
It is not possible to provide S3-locations without redefining the current L2-construct.
CDK source code:
aws-cdk/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts
Lines 236 to 243 in bf0113b
Proposed Solution
Provide S3-locations of the schema definition file and any resolver mapping templates to the synthesized template using CloudFormation parameters, similar to CfnParametersCode (see example here).
Since the number of mapping templates can be very high, a solution that requires only one parameter representing the S3-folder containing the mapping templates would be useful.
Creating an AppSync API and mapping templates could look like:
Other
Related question on Gitter.
This is a 🚀 Feature Request