Deploying Serverless GraphQL APIs with TypeScript on Netlify
Deploying a Serverless GraphQL API with TypeScript is essentially the same as deploying one with JavaScript.
The only difference is in the build steps.
For example, using vanilla JavaScript on Netlify, the build step in our package.json
is usually to copy all of the vanilla JavaScript code in our src
folder over to the functions
folder.
{
"scripts": {
"start": "nodemon",
"bundle": "cpx src/**/* functions/bundle" }
}
While building with TypeScript is effectively the same, just through different means. In a TypeScript environment, we configure a tsconfig.json
and run tsc
as the build step.
{
"compilerOptions": {
"allowJs": true,
"module": "commonjs",
"moduleResolution": "node",
"pretty": true,
"sourceMap": true,
"target": "es2017",
"outDir": "./functions/bundle", "lib": ["es6"],
"resolveJsonModule": true,
"types": ["node"],
"typeRoots" : ["./node_modules/@types", "./src/@types"],
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true
},
"include": [
"src/*.ts",
"src/**/*.ts",
"src/**/*.js"
],
"exclude": [
"node_modules",
"src/**/*.spec.ts",
"src/**/*.spec.js"
]
}
{
"scripts": {
"start": "nodemon",
"bundle": "tsc" }
}
Either way, the result is the same since Netlify needs all of the source code used in the functions
direction to be bundled before it's deployed.
Resources
Check out these starters for deploying your own Serverless GraphQL APIs on Netlify with TypeScript or vanilla JavaScript.
Starters
- Serverless GraphQL on Netlify API Starter Project
- Serverless GraphQL on Netlify API using TypeScript Starter Project
Tutorial
If you're interested in how the starters were built, read "How to Deploy a Serverless GraphQL API on Netlify [Starters]".
Discussion
Liked this? Sing it loud and proud 👨‍🎤.
🚀 55% off The Software Essentialist sale - doors open in 3 days
A lot of devs get stuck in “best practices”.
Between things like SOLID, Clean Code, microservices, single-file components, and so on — there’s a lot you can do...
But in my experience, there’s only a small set of things that really matter at this stage when it comes to making the shift from coding to crafting.
There's only a few things that really move the needle in terms of writing scalable, testable code (on any side of the stack).
That's what the Best Practice-First Phase is all about: the real best practices.
We're doing a 55% off promo of The Software Essentialist from March 31st to April 4th to celebrate the launch of The Best Practice-First phase of craftship in the Early Adopter course.
Folks have been asking me to do one of these for a while, but I wanted to wait until this valuable module dropped.
Join the waitlist for bonuses and to get early bird access (1 to 5 hours before everyone else) when the sale goes live.
Only 200 spots available. Join the waitlist here đź”—.
PS: You can track updates on the course progress & the companion book (solidbook.io) here.
Stay in touch!
Join 15000+ value-creating Software Essentialists getting actionable advice on how to master what matters each week. đź––
View more in GraphQL
You may also enjoy...
A few more related articles