---
title: "Discussion on \"Improving Developer Experience with TypeScript: How to Write Strongly Typed AppSync Resolvers\" | Hashnode"
description: "Discussion on \"Improving Developer Experience with TypeScript: How to Write Strongly Typed AppSync Resolvers\". AppSync Resolvers in TypeScript, without Lambda"
url: "https://hashnode.com/posts/improving-developer-experience-with-typescript-how-to-write-strongly-typed-appsync-resolvers/6434f95af10e88e90acb51db"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Improving Developer Experience with TypeScript: How to Write Strongly Typed AppSync Resolvers](https://blog.graphbolt.dev/improving-developer-experience-with-typescript-how-to-write-strongly-typed-appsync-resolvers?utm_source=hashnode&utm_medium=feed)

AppSync Resolvers in TypeScript, without Lambda

Apr 11, 2023 · 6 min read · blog.graphbolt.dev  
Read the article

-   [#appsync](https://hashnode.com/tag/appsync)
-   [#graphql](https://hashnode.com/tag/graphql)
-   [#aws](https://hashnode.com/tag/aws)
-   [#serverless](https://hashnode.com/tag/serverless)
-   [#typescript](https://hashnode.com/tag/typescript)

## Written by

[Benoît Bouré](https://hashnode.com/@bboure)

@bboure · Remote

  
[View profile](https://hashnode.com/@bboure)

Software developer

👨‍💻 Sofware Engineer · 💬 Consultant · 🚀 Indie Maker · ⚡️ Serverless 🔧 serverless-appsync-plugin · serverless-appsync-simulator · middy-appsync 🐈 and 🍵

## Responses 4

Markdown supported · ⌘↵ to post

[sarahlison](https://hashnode.com/@sarahlison)

[May 21, 2024](https://hashnode.com/posts/improving-developer-experience-with-typescript-how-to-write-strongly-typed-appsync-resolvers/6434f95af10e88e90acb51db/comment/664c159c2e64d74a9ff5cd46)

Is there no way to completely fix the problem? I don't want such troubles to happen while the process is being done.

[Janusz](https://hashnode.com/@janush)

[Apr 10, 2024](https://hashnode.com/posts/improving-developer-experience-with-typescript-how-to-write-strongly-typed-appsync-resolvers/6434f95af10e88e90acb51db/comment/661663034039f366bb81815d)

Interesting article, although the statement that "AppSync uses the latest ES module version" is simply untrue and can lead to issues when working on something more than hello world. AWS docs clearly say that APPSYNC\_JS supports only a subset of ES 6 functionality, and ES 6 = ES2015, after 2015 we had 17, 18, 19, 20, 21, 22, 23 & 24, so it's doesn't even come close to ESNEXT, which basically means "take latest".

Unless we get real implementation of APPSYNC\_JS target for ESBuild we can only try to make things work. My suggestion would be to:

1.  Switch target to ES6
2.  Add one more step after the code gets transpiled that runs eslint configured with restricted AppSync syntax to make sure everything is up to the standard after transpilation

Unfortunately it's not a seamless experience as you can still stumble upon functionality that will transpile to something that can't work, but you would at least get clear error during build step when it happens.

[Benoît Bouré](https://hashnode.com/@bboure)

[Apr 15, 2024](https://hashnode.com/posts/improving-developer-experience-with-typescript-how-to-write-strongly-typed-appsync-resolvers/6434f95af10e88e90acb51db/comment/661663034039f366bb81815d#reply-661cdf397363293a9a0c2ebb)

Thanks for all the details Janusz.

That statement looks misleading, indeed, and I could clarify this point.

However, the AppSycn documentation recommends esnext as the target. (Well, they don't expressly recommend it but this is what they show in the examples).

[docs.aws.amazon.com/appsync/latest/devguide/resol…](https://docs.aws.amazon.com/appsync/latest/devguide/resolver-reference-overview-js.html#additional-utilities)

When I first experimented with TS resolvers (even before the aforementioned doc was written), I experienced issues with most non-esnext targets, even those that were supposed to be compatible. esnext was the only one that worked every time.

I am not a pro at transpiling and EsBuild, but my experience showed that using "esnext" as the target ensures that the transpiler will usually not try to "transform" any of your code. When using TypeScript, it merely removes any typing and keeps everything else as-is. It also bundles everything in a single file. Which is exactly what I want.

It is the responsibility of the developer to ensure that the code will be APPSYNC\_JS compatible after that.

To avoid bad/incompatible code, I use the eslint plugin at development time. And if for any reason my code would still be incompatible, I would also get a warning from CloudFormations/AppSync's API.

with that said, I'd be happy to hear your experience with using other targets (es6) if you have tried it.

Thanks for commenting!

[Janusz](https://hashnode.com/@janush)

[Apr 15, 2024](https://hashnode.com/posts/improving-developer-experience-with-typescript-how-to-write-strongly-typed-appsync-resolvers/6434f95af10e88e90acb51db/comment/661663034039f366bb81815d#reply-661d4326cb105b8aca34ab1e)

Hey, thanks for the answer!

Recently I've been considering different approaches for my new typescript lambda projects and some of those considerations revolved around choices of commonjs / module project type, ES lib & build targets, node version, ts, prettier & eslint configurations and then compatibility of all of the above with DI, validation & testing libraries, CDK deployments etc. As you probably know, dealing with this stuff can push relatively sane person to the edge of insanity, so I may've been a bit sensitive about the topic when I saw "ESNEXT" recommendation in your article. So I'm sorry if I sounded hostile / attacky!

For now I was only considering AppSync as one of the options for new project we're working on within the company, so I just started playing with it and naturally landed in APPSYNC\_JS, but before going through overview I went straight to compatibility and found this: [docs.aws.amazon.com/appsync/latest/devguide/resol…](https://docs.aws.amazon.com/appsync/latest/devguide/resolver-util-reference-js.html) and then your article which immediately got me triggered as something was off.

Nevertheless it seems like you're right, and since AWS is posting those sorts of examples we may assume it's recommended way, even though it may seem to potentially contradict their own documentation (at least to my understanding, I may not be expert enough to be the judge here).

Off topic curiosity: beside looking into AppSync I also started checking out VTL mapping for both AppSync & API Gateway and man- if you didn't see documentation wild west then this is the place, ton of undocumented behaviors & limitations which answers to can be found everywhere but official docs.

Thanks for clarifying and have a good day, Cheers!

[Denise Ignatova](https://hashnode.com/@denise50)

[Jan 5, 2024](https://hashnode.com/posts/improving-developer-experience-with-typescript-how-to-write-strongly-typed-appsync-resolvers/6434f95af10e88e90acb51db/comment/659809c1ee193c570c911018)

Thank you for the tutorial, really amazing. I am getting \_\_filename is not defined error on deploy. Any thoughts?

[Benoît Bouré](https://hashnode.com/@bboure)

[Jan 17, 2024](https://hashnode.com/posts/improving-developer-experience-with-typescript-how-to-write-strongly-typed-appsync-resolvers/6434f95af10e88e90acb51db/comment/659809c1ee193c570c911018#reply-65a7dc1cd01ef177df367867)

It's hard to tell without any more context / code. when does this error show up?

[Dev Dev](https://hashnode.com/@devtestdev)

[Dec 11, 2023](https://hashnode.com/posts/improving-developer-experience-with-typescript-how-to-write-strongly-typed-appsync-resolvers/6434f95af10e88e90acb51db/comment/65769af232862421fba94490)

Thanks for the tutorial I just tried this out in my CDK Typescript project and it deploys fine, but when I try calling the endpoint Appsync throws "Unable to transform the template"

import esbuild from 'esbuild';

export function bundleResolver(entryPoint: string): string { const result = esbuild.buildSync({ entryPoints: \[entryPoint\], bundle: true, write: false, platform: 'node', target: 'esnext', format: 'esm', sourcemap: 'inline', sourcesContent: false, });

if (result?.outputFiles && result?.outputFiles?.length > 0 && result?.outputFiles\[0\]?.text) { return result.outputFiles\[0\].text; } else { throw new Error('Bundling failed: No output files generated'); } }

[Benoît Bouré](https://hashnode.com/@bboure)

[Dec 16, 2023](https://hashnode.com/posts/improving-developer-experience-with-typescript-how-to-write-strongly-typed-appsync-resolvers/6434f95af10e88e90acb51db/comment/65769af232862421fba94490#reply-657db47903e6d4749ace72a6)

Hi,

I have never seen that error. The first thing I would do is to double-check what code was generated and if it looks correct.

I might be wrong, but "Unable to transform the template" looks like a VTL error. Make sure you use the `code` property in the CDK and enable JS runtime.
