Relational Database Modeling for GraphQL

Rate this content
Bookmark

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 contents

Part 1 - Hour 1

      a. Relational Database Data Modeling

      b. Comparing Relational and NoSQL Databases

      c. GraphQL with the Database in mind

Part 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


This workshop has been presented at GraphQL Galaxy 2020, check out the latest edition of this Tech Conference.

FAQ

While it's not mandatory to follow along, participants who engage with the coding, design, and service setup activities will gain the most from the workshop. Familiarity with GraphQL, Postgres, and tools like DB Diagram, Hasura, and Heroku is beneficial for a hands-on experience.

Participants should have accounts with DB Diagram for database schema modeling, Hasura for handling GraphQL queries, and Heroku for backend database services. These tools will be used to design database schemas, manage GraphQL relationships, and host databases respectively.

The workshop is divided into two parts. The first part focuses on building a database schema and designing relational models. After a short break, the second part delves deeper into relational data models, multi-joined queries, and utilizing Hasura for GraphQL queries based on underlying database relationships.

To maximize learning, participants are encouraged to actively engage in the workshop by following along with the exercises, asking questions, and working through the content as presented. Access to the required software and accounts beforehand will facilitate a smoother experience.

Hasura is utilized for its ability to easily build GraphQL queries, manage database relationships, and interact directly with databases. Features such as the Explorer, CodeExporter, and the Hasura CLI for database migrations and metadata management are highlighted.

Adron Hall
Adron Hall
106 min
15 Jul, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

The workshop covers relational database modeling with GraphQL, focusing on building efficient database schemas and designing relational models. Participants will use tools like dbDiagram to visualize and create tables with primary and foreign keys, ensuring data consistency and optimal performance. Hasura is used for managing GraphQL queries, database relationships, and migrations. The workshop also touches on the use of UUIDs for primary keys to avoid conflicts and improve performance, especially in distributed databases. Real-world examples include setting up a database in Heroku, using Postgres, and exploring features like the Hasura CLI for automating tasks. The session emphasizes minimizing joins and using denormalized tables for faster queries, providing a comprehensive guide for tech professionals interested in optimizing their GraphQL and database workflows.

1. Introduction to Relational Modeling with GraphQL

Short description:

Welcome to today's workshop. I am Adrian. This is relational modeling with GraphQL in mind. We'll go through the first part, get a database schema built, design out some things, thank you Daria, and then we will take a short break, basically a bio break, before getting into part two. So part one, again, relational modeling, we'll build ourselves out an actual schema. Something kind of like this. That's dbDiagram by the way. So that's what we'll be working in. And then in part two, we'll get more into the relational data models. What we get when we do like multi-joined queries and the relationships within the database, but also from what we would get using a tool like Hasura, which I'll be using to show how it sees relationships and how it builds those together for the GraphQL queries based on the relationships and the modeling of the underlying database. And that is what the Hasura tool looks like. We'll be using primarily the GraphQL section, which makes it super easy to build out the GraphQL queries and we'll look at some of the other parts of it, like the Explorer, the CodeExporter, things like that. We'll also be looking at the data section to actually interact directly with the database in some of the design and everything. And to execute some of our initial SQL that we'll write out. And I may use the Hasura CLI a little bit. It's a great tool to get, if you're gonna use Hasura and you're gonna build yourself the development workflow around it, definitely get the CLI too. It's got a lot of great features around doing migrations, filling out the metadata, and just kind of working with and interacting through an automated way, or being able to build an automated pathway for your tooling. And then I'm gonna take the time to move on to the next part of your tooling.

Welcome to today's workshop. I am Adrian. This is relational modeling with GraphQL in mind. So there's a few prerequisites that pointed out. Of course, nobody has to follow along. However, I have this material very much oriented toward speaking about particular topics and then actually working through with all of you through the content.

So there's gonna be some coding, there's gonna be some design, and then there's going to actually be some spinning up of services and things like that. So if you do want to follow along to get the most from this workshop, you can absolutely do that. And I put here that I'll be using Postgres Docker a little bit, but I have actually made it so that I don't even need to use that. The only thing that you'll need is an account, which you can sign up for even right now, it's pretty quick to be able to do so, with DB diagram and Hasura and prospectively Heroku. Heroku will be providing the Postgres database back in for Hasura when I get to that part of the workshop. And there will be time to sign up for each of those quickly if you haven't done so yet.

I've split this into two parts. We'll go through the first part, get a database schema built, design out some things, thank you Daria, and then we will take a short break, basically a bio break, before getting into part two. So part one, again, relational modeling, we'll build ourselves out an actual schema. Something kind of like this. That's dbDiagram by the way. So that's what we'll be working in. And then in part two, we'll get more into the relational data models. What we get when we do like multi-joined queries and the relationships within the database, but also from what we would get using a tool like Hasura, which I'll be using to show how it sees relationships and how it builds those together for the GraphQL queries based on the relationships and the modeling of the underlying database. And that is what the Hasura tool looks like. We'll be using primarily the GraphQL section, which makes it super easy to build out the GraphQL queries and we'll look at some of the other parts of it, like the Explorer, the CodeExporter, things like that. We'll also be looking at the data section to actually interact directly with the database in some of the design and everything. And to execute some of our initial SQL that we'll write out. And I may use the Hasura CLI a little bit. It's a great tool to get, if you're gonna use Hasura and you're gonna build yourself the development workflow around it, definitely get the CLI too. It's got a lot of great features around doing migrations, filling out the metadata, and just kind of working with and interacting through an automated way, or being able to build an automated pathway for your tooling. And then I'm gonna take the time to move on to the next part of your tooling.

2. Introduction to Relational Concepts

Short description:

We'll start with relational concepts and briefly mention NoSQL databases. The focus will be on relational databases, but I'll touch on other types as well. If you're interested in learning more, follow me and sign up for future workshops and events. I have experience with various database types.

All right, we're gonna start off with relational concepts. I will mention a few things about NoSQL databases. Primarily though, this entire workshop is going to be relational database oriented. So focused on the ideas behind that. But I'll mention some of the others because they are quite prevalent these days. And there's a lot of shared concepts between a lot of these. And it helps to know the difference between the concepts there versus the concepts in the relational model. So I'll mention that in a few parts.

And those things that I mentioned primarily are only focused around the columnar and document based distributed databases like Mongo and Apache Cassandra. And I'll mention a little bit about graph databases like Neo4j or something like that. Neo4j, Titan and the other ones. Not gonna bring up Time Series. I'm not gonna bring up some of the other NoSQL niche databases at this point. However, if you are curious, be sure to follow me and sign up for future workshops and events at Hasura and under my accounts which I will provide at the end of this. So no reason to worry about those right now. I do a lot of streaming and other things like that around all sorts of database types. So I've done a lot of work in that, love to share it.

QnA

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
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.
How to Solve Real-World Problems with Remix
Remix Conf Europe 2022Remix Conf Europe 2022
195 min
How to Solve Real-World Problems with Remix
Featured Workshop
Michael Carter
Michael Carter
- Errors? How to render and log your server and client errorsa - When to return errors vs throwb - Setup logging service like Sentry, LogRocket, and Bugsnag- Forms? How to validate and handle multi-page formsa - Use zod to validate form data in your actionb - Step through multi-page forms without losing data- Stuck? How to patch bugs or missing features in Remix so you can move ona - Use patch-package to quickly fix your Remix installb - Show tool for managing multiple patches and cherry-pick open PRs- Users? How to handle multi-tenant apps with Prismaa - Determine tenant by host or by userb - Multiple database or single database/multiple schemasc - Ensures tenant data always separate from others
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.

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.
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.
Batteries Included Reimagined - The Revival of GraphQL Yoga
GraphQL Galaxy 2021GraphQL Galaxy 2021
33 min
Batteries Included Reimagined - The Revival of GraphQL Yoga
Envelope is a powerful GraphQL plugin system that simplifies server development and allows for powerful plugin integration. It provides conformity for large corporations with multiple GraphQL servers and can be used with various frameworks. Envelope acts as the Babel of GraphQL, allowing the use of non-spec features. The Guild offers GraphQL Hive, a service similar to Apollo Studio, and encourages collaboration with other frameworks and languages.
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
The Talk discusses the challenges and advancements in using GraphQL and React together. It introduces RedwoodJS, a framework that simplifies frontend-backend integration and provides features like code generation, scaffolding, and authentication. The Talk demonstrates how to set up a Redwood project, generate layouts and models, and perform CRUD operations. Redwood automates many GraphQL parts and provides an easy way for developers to get started with GraphQL. It also highlights the benefits of Redwood and suggests checking out RedwoodJS.com for more information.
Adopting GraphQL in an Enterprise
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
Adopting GraphQL in an Enterprise
Today's Talk is about adopting GraphQL in an enterprise. It discusses the challenges of using REST APIs and the benefits of GraphQL. The Talk explores different approaches to adopting GraphQL, including coexistence with REST APIs. It emphasizes the power of GraphQL and provides tips for successful adoption. Overall, the Talk highlights the advantages of GraphQL in terms of efficiency, collaboration, and control over APIs.
Step aside resolvers: a new approach to GraphQL execution
GraphQL Galaxy 2022GraphQL Galaxy 2022
16 min
Step aside resolvers: a new approach to GraphQL execution
GraphQL has made a huge impact in the way we build client applications, websites, and mobile apps. Despite the dominance of resolvers, the GraphQL specification does not mandate their use. Introducing Graphast, a new project that compiles GraphQL operations into execution and output plans, providing advanced optimizations. In GraphFast, instead of resolvers, we have plan resolvers that deal with future data. Graphfast plan resolvers are short and efficient, supporting all features of modern GraphQL.