We are in the process of enhancing our API by adding new JS resolvers and phasing out the VTL resolvers for an AWS AppSync CDK project, specifically built with Cfn<> Cloud Front CDK. The code snippet below illustrates how this can be achieved:
let resolver = new CfnResolver(this, `${r.typeName}_${r.fieldName}`, {
apiId: graphql.attrApiId,
typeName: r.typeName,
fieldName: r.fieldName,
dataSourceName: r.dataSourceName,
requestMappingTemplate: readVtl(reqPath, contextVariables),
responseMappingTemplate: readVtl(resPath, contextVariables),
});
All recent examples from AWS CDK Example showcase the use of AppSync CDK following this approach.
new appsync.Resolver(this, 'pipeline-resolver-create-posts', {
api,
typeName: 'Mutation',
fieldName: 'createPost',
code: appsync.Code.fromInline(`
export function request(ctx) {
return {};
}
export function response(ctx) {
return ctx.prev.result;
}
`),
runtime: appsync.FunctionRuntime.JS_1_0_0,
pipelineConfig: [add_func_2],
});
I am facing challenges in getting the CfnResolver to accept new JS resolvers. I have explored various options without success and referred to the AWS documentation here
let resolver = new CfnResolver(this, `${r.typeName}_${r.fieldName}`, {
apiId: graphql.attrApiId,
typeName: r.typeName,
fieldName: r.fieldName,
dataSourceName: r.dataSourceName,
code: readJs(reqPath, contextVariables),
runtime: CfnResolver.AppSyncRunTime.JS_1_0_0 <-- DOESNT WORK
});
Could someone provide guidance on what might be going wrong or whether transitioning from Cfn CDK to direct AppSync CDK is a better option? Thank you.