Skip to content

sudokar/cdk-appsync-typescript-resolver

Repository files navigation

cdk-appsync-typescript-resolver

npm (scoped) Codacy Badge GitHub Workflow Status (branch) GitHub release (latest SemVer) License PRs Welcome Maintained Gitpod ready-to-code

Constructs to transpile and bundle Typescript to valid AWS Appsync's JS resolvers

View on Construct Hub

✨ Constructs

🚀 Usage

  • TypescriptUnitResolver
import { TypescriptUnitResolver } from 'cdk-appsync-typescript-resolver'

const resolver = new TypescriptUnitResolver(stack, "DemoResolver", {
    api: new appsync.GraphqlApi(...),
    typeName: "Query",
    fieldName: "hello",
    path: path.join(__dirname, "path", "to", "file.ts"),
    sourceMap: true,
});
  • AppsyncTypescriptFunction
import { AppsyncTypescriptFunction } from 'cdk-appsync-typescript-resolver'
...
const appsyncFunction = new AppsyncTypescriptFunction(stack, "TSDemoFunction", {
    name: "TSDemoFunction",
    api: new appsync.GraphqlApi(...),
    path: path.join(__dirname, "path", "to", "file.ts"),
    dataSource: new appsync.DynamoDbDataSource(...),
    sourceMap: true,
});

Tip: Use GraphQL Code Generator to generate Typescript types from GraphQL schema(s) to use in resolvers

Checkout the demo project for examples cdk-appsync-typescript-resolver-demo

References

JavaScript resolvers overview

Bundling, TypeScript, and source maps

GraphQL Code Generator