Fullstack Type-Safety with GraphQL and Hasura

Rate this content
Bookmark

In this workshop, we’ll learn how to build a type-safe chain from API to the client with generated TypeScript tooling. Creating a type-safe environment for development reduces the number of bugs that get shipped to production, but also creates faster feature development once the ground-work is in place.

This will be a fast-paced workshop covering an opinionated stack of features, but in the end, you’ll have a functioning framework for eloquent and type-safe development.

Table of contents

- We’ll begin creating a GraphQL API on Hasura Cloud and define some basic access controls and actions.
- Then we’ll scaffold a TypeScript-ready framework with NextJs.
- With the framework and API in place, we’ll generate an SDK using GraphQL Zeus.
- Lastly, we’ll generate some type-safe state management wrappers with easy-peasy for implementing a basic login and authentication flow.

FAQ

GraphQL Zeus is a library that generates typings and a local SDK for GraphQL endpoints, facilitating a tightly coupled interaction between the GraphQL server and front-end applications. It allows for querying data in a structured, predictable way with the convenience of type checking.

The Apollo Client in Next.js is configured to work with server-side and client-side data fetching. It includes setting up a fetch policy, handling cookies for authentication purposes, and integrating with Next.js's hydration features for efficient data management across client and server.

Easy Peasy is used for state management in the application, providing a straightforward way to manage global state with hooks. It allows for defining models, actions, and thunks, making it easier to handle state changes and asynchronous operations in a React application.

The issue with the HTTP cookie not being set during the demonstration could be related to the browser or server settings, such as security configurations that prevent cookies from being set properly. It might also involve issues with the response handling in the application code.

Debugging in GraphQL applications can involve inspecting network requests and responses, checking the GraphQL queries and mutations for errors, and using developer tools to monitor the state and performance of the application. Proper logging and error handling strategies are also crucial.

Jesse Martin
Jesse Martin
203 min
19 Oct, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

This workshop explores back to front type safety in building front-end applications using TypeScript and Next.js. It covers setting up a cloud project with Hazura, creating login and signup actions, handling API endpoints with a Next.js application, and querying and displaying user data using Apollo Client. The workshop also includes setting up state management with easy peasy and debugging authentication and state management issues. Overall, it provides insights into building future-proof, stable, and secure apps using these tools and technologies.

1. Introduction to Back to Front Type Safety

Short description:

In this workshop, we will be exploring back to front type safety. We will generate a GraphQL layer for type safety in building front end applications using TypeScript and Next.js. TypeScript helps reduce bugs in production code. Let's learn how to build more future-proof, stable, and secure apps using these tools and technologies.

My name is Jesse. I am going to be leading, working with you today in this workshop. And I am a developer outreach person for Hazura. Hazura is a cloud provider and beta layer provider doing all kinds of amazing things. If you are not familiar with us, definitely check it out. We'll be having a look at some of what it does today. And this is the back to front type safety workshop.

What does that mean? That means that we are starting with a concept of generating a GraphQL layer that is going to be our type starting point. And we'll be using that to generate an SDK to essentially give us type safety for building front end applications using a TypeScript application for Next.js.

Now, here's some critical pieces to know about that process. One is, I'm not a TypeScript guru. So, I'm like the sweet spot of what TypeScript is actually supposed to be solving. And maybe many of you are as well. TypeScript is actually helping us produce less bugs in our code that we ship to production. So, there will be some cases where maybe even many of you know the answer better if a TypeScript error arises. And in that case, I would love to have you let me know. I'm not proud. I'm not going to pretend like I'm the TypeScript person. I am a GraphQL person. I am a data modeling person. So, questions around that, I'm definitely happy to help with. But this is basically all of us learning how do we build apps in a more future proof, more stable, more secure way going forward with some tools and technologies that really have provided a lot of stability and yeah, type safe footprint for the community as a whole. So, that's basically the premise.

2. Introduction and Workshop Guidelines

Short description:

We're going to start from scratch and build this together. Feel free to turn on your cameras, ask questions, and code along. Let's make this a collaborative experience.

What I have, if you'll see the GitHub repo, we're going to start from scratch. And as we go through, I will be pasting code both inside of the, you'll be seeing the code inside of the window. We'll build this together. And then I'll be making most of that code available through the repo. And what I'm wondering, because at the moment, nobody else is turning on their cameras. So, it may just be, you know, a bit of watching me code today from what it's looking like. Hey, I've got somebody.

What we may do is I may just start to flesh out this repo as we go through and then we'll be able to kind of keep pushing it forward. So, I really appreciate having the first camera on. This is a casual workshop. This is not a here's my slides and please don't ask me any questions. Everybody is allowed to turn on the cameras. You're allowed to interject, raise your hands, have a question. We've got breakout rooms available. If there's a spot where we say, hey, let's go ahead and take five minutes and let, we'll break it up into smaller groups to kind of figure out what we're doing. But it's meant today that everybody can kind of code together. So, does that sound good? Are there any questions before I get started? I'm looking at Zoom. I'm looking at Discord.

Watch more workshops on topic

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
Developing Dynamic Blogs with SvelteKit & Storyblok: A Hands-on Workshop
JSNation 2023JSNation 2023
174 min
Developing Dynamic Blogs with SvelteKit & Storyblok: A Hands-on Workshop
Top Content
Featured WorkshopFree
Alba Silvente Fuentes
Roberto Butti
2 authors
This SvelteKit workshop explores the integration of 3rd party services, such as Storyblok, in a SvelteKit project. Participants will learn how to create a SvelteKit project, leverage Svelte components, and connect to external APIs. The workshop covers important concepts including SSR, CSR, static site generation, and deploying the application using adapters. By the end of the workshop, attendees will have a solid understanding of building SvelteKit applications with API integrations and be prepared for deployment.
End-To-End Type Safety with React, GraphQL & Prisma
React Advanced Conference 2022React Advanced Conference 2022
95 min
End-To-End Type Safety with React, GraphQL & Prisma
Featured WorkshopFree
Sabin Adams
Sabin Adams
In this workshop, you will get a first-hand look at what end-to-end type safety is and why it is important. To accomplish this, you’ll be building a GraphQL API using modern, relevant tools which will be consumed by a React client.
Prerequisites: - Node.js installed on your machine (12.2.X / 14.X)- It is recommended (but not required) to use VS Code for the practical tasks- An IDE installed (VSCode recommended)- (Good to have)*A basic understanding of Node.js, React, and TypeScript
GraphQL for React Developers
GraphQL Galaxy 2022GraphQL Galaxy 2022
112 min
GraphQL for React Developers
Featured Workshop
Roy Derks
Roy Derks
There are many advantages to using GraphQL as a datasource for frontend development, compared to REST APIs. We developers in example need to write a lot of imperative code to retrieve data to display in our applications and handle state. With GraphQL you cannot only decrease the amount of code needed around data fetching and state-management you'll also get increased flexibility, better performance and most of all an improved developer experience. In this workshop you'll learn how GraphQL can improve your work as a frontend developer and how to handle GraphQL in your frontend React application.
Build a Headless WordPress App with Next.js and WPGraphQL
React Summit 2022React Summit 2022
173 min
Build a Headless WordPress App with Next.js and WPGraphQL
Top Content
WorkshopFree
Kellen Mace
Kellen Mace
In this workshop, you’ll learn how to build a Next.js app that uses Apollo Client to fetch data from a headless WordPress backend and use it to render the pages of your app. You’ll learn when you should consider a headless WordPress architecture, how to turn a WordPress backend into a GraphQL server, how to compose queries using the GraphiQL IDE, how to colocate GraphQL fragments with your components, and more.
Relational Database Modeling for GraphQL
GraphQL Galaxy 2020GraphQL Galaxy 2020
106 min
Relational Database Modeling for GraphQL
Top Content
WorkshopFree
Adron Hall
Adron Hall
In this workshop we'll dig deeper into data modeling. We'll start with a discussion about various database types and how they map to GraphQL. Once that groundwork is laid out, the focus will shift to specific types of databases and how to build data models that work best for GraphQL within various scenarios.
Table of contentsPart 1 - Hour 1      a. Relational Database Data Modeling      b. Comparing Relational and NoSQL Databases      c. GraphQL with the Database in mindPart 2 - Hour 2      a. Designing Relational Data Models      b. Relationship, Building MultijoinsTables      c. GraphQL & Relational Data Modeling Query Complexities
Prerequisites      a. Data modeling tool. The trainer will be using dbdiagram      b. Postgres, albeit no need to install this locally, as I'll be using a Postgres Dicker image, from Docker Hub for all examples      c. Hasura

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
We all love GraphQL, but it can be daunting to get a server up and running and keep your code organized, maintainable, and testable over the long term. No more! Come watch as I go from an empty directory to a fully fledged GraphQL API in minutes flat. Plus, see how easy it is to use and create directives to clean up your code even more. You're gonna love GraphQL even more once you make things Redwood Easy!
Full Stack Components
Remix Conf Europe 2022Remix Conf Europe 2022
37 min
Full Stack Components
Top Content
Remix is a web framework that gives you the simple mental model of a Multi-Page App (MPA) but the power and capabilities of a Single-Page App (SPA). One of the big challenges of SPAs is network management resulting in a great deal of indirection and buggy code. This is especially noticeable in application state which Remix completely eliminates, but it's also an issue in individual components that communicate with a single-purpose backend endpoint (like a combobox search for example).
In this talk, Kent will demonstrate how Remix enables you to build complex UI components that are connected to a backend in the simplest and most powerful way you've ever seen. Leaving you time to chill with your family or whatever else you do for fun.
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
How many times did you implement the same flow in your application: check, if data is already fetched from the server, if yes - render the data, if not - fetch this data and then render it? I think I've done it more than ten times myself and I've seen the question about this flow more than fifty times. Unfortunately, our go-to state management library, Vuex, doesn't provide any solution for this.For GraphQL-based application, there was an alternative to use Apollo client that provided tools for working with the cache. But what if you use REST? Luckily, now we have a Vue alternative to a react-query library that provides a nice solution for working with server cache. In this talk, I will explain the distinction between local application state and local server cache and do some live coding to show how to work with the latter.
RedwoodJS: The Full-Stack React App Framework of Your Dreams
React Summit Remote Edition 2021React Summit Remote Edition 2021
43 min
RedwoodJS: The Full-Stack React App Framework of Your Dreams
Top Content
Tired of rebuilding your React-based web framework from scratch for every new project? You're in luck! RedwoodJS is a full-stack web application framework (think Rails but for JS/TS devs) based on React, Apollo GraphQL, and Prisma 2. We do the heavy integration work so you don't have to. We also beautifully integrate Jest and Storybook, and offer built-in solutions for declarative data fetching, authentication, pre-rendering, logging, a11y, and tons more. Deploy to Netlify, Vercel, or go oldschool on AWS or bare metal. In this talk you'll learn about the RedwoodJS architecture, see core features in action, and walk away with a sense of wonder and awe in your heart.
Batteries Included Reimagined - The Revival of GraphQL Yoga
GraphQL Galaxy 2021GraphQL Galaxy 2021
33 min
Batteries Included Reimagined - The Revival of GraphQL Yoga
The Guild has recently released Envelop - a new, modern GraphQL Server Framework and plugin system. In this talk I’ll share a brief overview of Envelop and why you should probably upgrade your existing GraphQL server to it.
Rock Solid React and GraphQL Apps for People in a Hurry
GraphQL Galaxy 2022GraphQL Galaxy 2022
29 min
Rock Solid React and GraphQL Apps for People in a Hurry
In this talk, we'll look at some of the modern options for building a full-stack React and GraphQL app with strong conventions and how this can be of enormous benefit to you and your team. We'll focus specifically on RedwoodJS, a full stack React framework that is often called 'Ruby on Rails for React'.