AppSync GraphQL resolvers can be written in JavaScript instead of VTL. AppSync has dev-time helpers for TypeScript resolvers, but we must bundle the code ourselves.
How can I bundle .ts
resolvers in the CDK?
We pass the resolver code to the CDK AppsyncFunction construct. But we can t directly pass a my-resolver.ts
file. Instead, appsync.Code.fromAsset
needs my-resolver.js
. Right now there isn t a batteries-included esbuild
local bundling option like the one NodejsLambda construct has.
const resolverFunc = new appsync.AppsyncFunction(this, "MyResolverFunc", {
name: "my_resolver",
api,
dataSource: dynamoDataSource,
code: appsync.Code.fromAsset(
path.join(__dirname, "../path/to/my_resolver.ts") // <- ❌ need a .js file here
),
runtime: appsync.FunctionRuntime.JS_1_0_0,
});