Building Real-time Serverless GraphQL APIs on AWS with TypeScript and CDK

Rate this content
Bookmark

CDK (Cloud development kit) enables developers to build cloud infrastructure using popular programming languages like Python, Typescript, or JavaScript. CDK is a next-level abstraction in infrastructure as code, allowing developers who were traditionally unfamiliar with cloud computing to build scalable APIs and web services using their existing skillset, and do so in only a few lines of code.


In this talk, you’ll learn how to use the TypeScript flavor of CDK to build a hyper-scalable real-time API with GraphQL, Lambda, DynamoDB, and AWS AppSync . At the end of the talk, I’ll live code an API from scratch in just a couple of minutes and then test out queries, mutations, and subscriptions.


By the end of the talk, you should have a good understanding of GraphQL, AppSync, and CDK and be ready to build an API in your next project using TypeScript and CDK.

This talk has been presented at React Summit 2020, check out the latest edition of this React Conference.

FAQ

The new JavaScript website offers free articles, videos, courses, and tutorials to help you learn all about React.

You can learn more about the new React.js courses by clicking the link in the description provided on the website.

GraphQL is a query language for your API that allows you to request specific data, reducing latency and providing more control over the data sent and received.

A GraphQL API is made up of three main parts: the schema, resolvers, and data sources. The schema defines data types and operations, resolvers map operations to data sources, and data sources provide the data.

AWS AppSync is a managed GraphQL service that provides a consistent API layer for any AWS service or data source, with built-in enterprise security features and easy integration for real-time subscriptions.

GraphQL provides more control over data fetching, allowing for lower latency and more efficient data transfer compared to REST. GraphQL uses queries, mutations, and subscriptions, whereas REST uses HTTP verbs like GET, POST, PUT, and DELETE.

GraphQL subscriptions enable real-time communication between a client and an API. They allow you to subscribe to events such as create, update, or delete operations, providing real-time updates.

AWS CDK (Cloud Development Kit) is a framework for defining cloud infrastructure using programming languages like TypeScript, JavaScript, and Python. It allows you to write infrastructure as code and supports multiple cloud providers, including AWS and Azure.

AppSync and CDK work together by allowing you to define and deploy GraphQL APIs and their infrastructure using code. You can create APIs, data sources, and resolvers with CDK, and manage real-time subscriptions with AppSync.

Using GraphQL with AppSync and CDK provides benefits such as simplified API management, real-time data updates, scalable infrastructure, and the ability to write infrastructure as code using familiar programming languages.

Nader Dabit
Nader Dabit
25 min
17 Jun, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

The video delves into building real-time serverless GraphQL APIs using TypeScript, AWS AppSync, and CDK. It starts with an introduction to GraphQL, highlighting its ability to define schemas, handle operations using resolvers, and manage data sources. AWS AppSync is showcased as a managed service that simplifies GraphQL API construction, supporting real-time subscriptions for dynamic data updates. CDK is introduced as a tool for writing infrastructure as code, with a live coding demo illustrating the setup of a GraphQL API, Lambda functions, and DynamoDB tables. The video emphasizes the benefits of using GraphQL for efficient data queries and real-time updates, especially in a serverless environment. Key topics include GraphQL subscriptions, AWS SDKs for AppSync, and leveraging TypeScript for cloud development.

1. Introduction to JavaScript and React

Short description:

We've created a new website for you to explore the world of JavaScript. We're bringing free articles, videos, courses, and tutorials to help you learn all about React.

We've created a new website for you to explore the world of JavaScript. We're bringing free articles, videos, courses, and tutorials to help you learn all about React. Click the link in the description to learn about all the new 하고 and react.js courses. We've also created a new playlist for you to check out. We've added many new courses, and we're also bringing free articles to the web and mobile in the future. Check out the link in the description to learn more about all the other courses we've created. Click the link in the description to learn more about all the other courses we've created.

2. Building Real-Time Serverless GraphQL APIs

Short description:

I'm going to be talking about building real-time serverless GraphQL APIs with TypeScript, AppSync, and CDK. We'll start with an introduction to GraphQL, then discuss AWS AppSync and Manage GraphQL Service, followed by a brief intro to CDK. I'll also do a live coding demo to demonstrate how all these components work together. GraphQL allows you to define a schema that represents your data types and operations. It offers more control over API latency and data transfer, returning responses in JSON. A GraphQL API consists of three main parts, starting with the schema.

Okay, hello everyone and thank you so much for attending my talk today. I'm really excited to be talking about this subject because it's something that I've been really using a lot lately and it's really powerful. So, I'm going to be talking about building real-time serverless GraphQL APIs with TypeScript, AppSync, and CDK. My name is Nader Dabit, I'm a Senior Developer Advocate and I'm by trade a front-end and mobile developer. And I've just now been working with AWS and back-end services for the last couple of years. And lately, I've really been focusing on building full-stack cloud and full-stack serverless apps. So, let's go ahead and jump right in because we have a lot to cover.

I'm going to be talking about a couple of things and they all kind of fit together. So, we're going to first start off with an introduction to GraphQL. We're going to then talk about AWS AppSync and Manage GraphQL Service. We're going to then do a brief intro to CDK. And then, we're going to kind of talk about how all of this stuff fits together, AppSync, CDK, and GraphQL. And then, I'm going to do a live coding demo. And I think the live coding demo kind of will show you how all this stuff works together better than any presentation will. But hopefully, putting all this together will be really helpful for you and you'll learn something.

So, let's talk about GraphQL for a bit. GraphQL, if you look it up on the internet and you find the definition, you might see something like this. A query language for your API. This doesn't say a whole lot. Let's dive a little bit deeper. With GraphQL, you have your, almost like a menu of your data, which is your GraphQL schema. The schema has all of the different data types, which are basically types, and all of the operations against those types. So, you have maybe a to-do app. You might think of something like a to-do type. And then, you might have operations for creating, reading, updating, and deleting your to-dos. All that is defined in your schema. And, once you've deployed your API, and we're going to talk about that a little bit more in just a moment, you can then just ask for the data that you want. And this is kind of the thing you've probably heard about before, if you've ever looked into GraphQL, is, one of the really powerful things about it is, you have the ability to build much lower latency and more, I guess, controlled APIs than when you're working with REST endpoints because you have a lot more control about the data that is getting sent back and forth across the wire, and then you get your response data returned to you in JSON.

So a GraphQL API is made up of three main parts. You have your schema, which we talk about in just a second there.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

From GraphQL Zero to GraphQL Hero with RedwoodJS
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
From GraphQL Zero to GraphQL Hero with RedwoodJS
Top Content
Tom Pressenwurter introduces Redwood.js, a full stack app framework for building GraphQL APIs easily and maintainably. He demonstrates a Redwood.js application with a React-based front end and a Node.js API. Redwood.js offers a simplified folder structure and schema for organizing the application. It provides easy data manipulation and CRUD operations through GraphQL functions. Redwood.js allows for easy implementation of new queries and directives, including authentication and limiting access to data. It is a stable and production-ready framework that integrates well with other front-end technologies.
React's Most Useful Types
React Day Berlin 2023React Day Berlin 2023
21 min
React's Most Useful Types
Top Content
Watch video: React's Most Useful Types
Today's Talk focuses on React's best types and JSX. It covers the types of JSX and React components, including React.fc and React.reactnode. The discussion also explores JSX intrinsic elements and react.component props, highlighting their differences and use cases. The Talk concludes with insights on using React.componentType and passing components, as well as utilizing the react.element ref type for external libraries like React-Select.
TypeScript and React: Secrets of a Happy Marriage
React Advanced Conference 2022React Advanced Conference 2022
21 min
TypeScript and React: Secrets of a Happy Marriage
Top Content
React and TypeScript have a strong relationship, with TypeScript offering benefits like better type checking and contract enforcement. Failing early and failing hard is important in software development to catch errors and debug effectively. TypeScript provides early detection of errors and ensures data accuracy in components and hooks. It offers superior type safety but can become complex as the codebase grows. Using union types in props can resolve errors and address dependencies. Dynamic communication and type contracts can be achieved through generics. Understanding React's built-in types and hooks like useState and useRef is crucial for leveraging their functionality.
Local State and Server Cache: Finding a Balance
Vue.js London Live 2021Vue.js London Live 2021
24 min
Local State and Server Cache: Finding a Balance
Top Content
This Talk discusses handling local state in software development, particularly when dealing with asynchronous behavior and API requests. It explores the challenges of managing global state and the need for actions when handling server data. The Talk also highlights the issue of fetching data not in Vuex and the challenges of keeping data up-to-date in Vuex. It mentions alternative tools like Apollo Client and React Query for handling local state. The Talk concludes with a discussion on GitLab going public and the celebration that followed.
Making Magic: Building a TypeScript-First Framework
TypeScript Congress 2023TypeScript Congress 2023
31 min
Making Magic: Building a TypeScript-First Framework
Top Content
Daniel Rowe discusses building a TypeScript-first framework at TypeScript Congress and shares his involvement in various projects. Nuxt is a progressive framework built on Vue.js, aiming to reduce friction and distraction for developers. It leverages TypeScript for inference and aims to be the source of truth for projects. Nuxt provides type safety and extensibility through integration with TypeScript. Migrating to TypeScript offers long-term maintenance benefits and can uncover hidden bugs. Nuxt focuses on improving existing tools and finds inspiration in frameworks like TRPC.
Stop Writing Your Routes
Vue.js London 2023Vue.js London 2023
30 min
Stop Writing Your Routes
Designing APIs is a challenge, and it's important to consider the language used and different versions of the API. API ergonomics focus on ease of use and trade-offs. Routing is a misunderstood aspect of API design, and file-based routing can simplify it. Unplugging View Router provides typed routes and eliminates the need to pass routes when creating the router. Data loading and handling can be improved with data loaders and predictable routes. Handling protected routes and index and ID files are also discussed.

Workshops on related topic

React, TypeScript, and TDD
React Advanced Conference 2021React Advanced Conference 2021
174 min
React, TypeScript, and TDD
Top Content
Featured WorkshopFree
Paul Everitt
Paul Everitt
ReactJS is wildly popular and thus wildly supported. TypeScript is increasingly popular, and thus increasingly supported.

The two together? Not as much. Given that they both change quickly, it's hard to find accurate learning materials.

React+TypeScript, with JetBrains IDEs? That three-part combination is the topic of this series. We'll show a little about a lot. Meaning, the key steps to getting productive, in the IDE, for React projects using TypeScript. Along the way we'll show test-driven development and emphasize tips-and-tricks in the IDE.
Mastering advanced concepts in TypeScript
React Summit US 2023React Summit US 2023
132 min
Mastering advanced concepts in TypeScript
Top Content
Featured WorkshopFree
Jiri Lojda
Jiri Lojda
TypeScript is not just types and interfaces. Join this workshop to master more advanced features of TypeScript that will make your code bullet-proof. We will cover conditional types and infer notation, template strings and how to map over union types and object/array properties. Each topic will be demonstrated on a sample application that was written with basic types or no types at all and we will together improve the code so you get more familiar with each feature and can bring this new knowledge directly into your projects.
You will learn:- - What are conditional types and infer notation- What are template strings- How to map over union types and object/array properties.
Deep TypeScript Tips & Tricks
Node Congress 2024Node Congress 2024
83 min
Deep TypeScript Tips & Tricks
Top Content
Featured Workshop
Josh Goldberg
Josh Goldberg
TypeScript has a powerful type system with all sorts of fancy features for representing wild and wacky JavaScript states. But the syntax to do so isn't always straightforward, and the error messages aren't always precise in telling you what's wrong. Let's dive into how many of TypeScript's more powerful features really work, what kinds of real-world problems they solve, and how to wrestle the type system into submission so you can write truly excellent TypeScript code.
Build with SvelteKit and GraphQL
GraphQL Galaxy 2021GraphQL Galaxy 2021
140 min
Build with SvelteKit and GraphQL
Top Content
Featured WorkshopFree
Scott Spence
Scott Spence
Have you ever thought about building something that doesn't require a lot of boilerplate with a tiny bundle size? In this workshop, Scott Spence will go from hello world to covering routing and using endpoints in SvelteKit. You'll set up a backend GraphQL API then use GraphQL queries with SvelteKit to display the GraphQL API data. You'll build a fast secure project that uses SvelteKit's features, then deploy it as a fully static site. This course is for the Svelte curious who haven't had extensive experience with SvelteKit and want a deeper understanding of how to use it in practical applications.

Table of contents:
- Kick-off and Svelte introduction
- Initialise frontend project
- Tour of the SvelteKit skeleton project
- Configure backend project
- Query Data with GraphQL
- Fetching data to the frontend with GraphQL
- Styling
- Svelte directives
- Routing in SvelteKit
- Endpoints in SvelteKit
- Deploying to Netlify
- Navigation
- Mutations in GraphCMS
- Sending GraphQL Mutations via SvelteKit
- Q&A
Best Practices and Advanced TypeScript Tips for React Developers
React Advanced Conference 2022React Advanced Conference 2022
148 min
Best Practices and Advanced TypeScript Tips for React Developers
Top Content
Featured Workshop
Maurice de Beijer
Maurice de Beijer
Are you a React developer trying to get the most benefits from TypeScript? Then this is the workshop for you.In this interactive workshop, we will start at the basics and examine the pros and cons of different ways you can declare React components using TypeScript. After that we will move to more advanced concepts where we will go beyond the strict setting of TypeScript. You will learn when to use types like any, unknown and never. We will explore the use of type predicates, guards and exhaustive checking. You will learn about the built-in mapped types as well as how to create your own new type map utilities. And we will start programming in the TypeScript type system using conditional types and type inferring.
Build Modern Applications Using GraphQL and Javascript
Node Congress 2024Node Congress 2024
152 min
Build Modern Applications Using GraphQL and Javascript
Featured Workshop
Emanuel Scirlet
Miguel Henriques
2 authors
Come and learn how you can supercharge your modern and secure applications using GraphQL and Javascript. In this workshop we will build a GraphQL API and we will demonstrate the benefits of the query language for APIs and what use cases that are fit for it. Basic Javascript knowledge required.