Build and Deploy Instant GraphQL APIs to the Edge

Rate this content
Bookmark

Learn how to generate instant GraphQL APIs using a data source connector (GraphQL and non-GraphQL sources), extend and join them both with custom resolvers and deploy to the edge without leaving the code editor.

This workshop has been presented at React Summit US 2023, check out the latest edition of this React Conference.

FAQ

Graphbase is a platform that allows developers to build GraphQL APIs on top of various data sources like Postgres, MongoDB, and OpenAPI. It offers edge caching to improve response times and reduce latency.

GraphQL allows developers to interface with various services using a single API, reducing the complexity of managing multiple APIs. It provides a more efficient way to fetch and manipulate data compared to traditional REST APIs.

GraphQL edge caching in Graphbase places a caching layer in front of your data sources. When a request is made, the data is cached, significantly reducing response times for subsequent requests. This helps in reducing latency and improving performance.

To connect Graphbase to a Postgres database, you need to use the Postgres connector in your Graphbase configuration file. You provide the connection string to your Postgres database, and Graphbase will automatically introspect the database and generate a GraphQL API.

Yes, Graphbase can work with other database types like MongoDB. It also supports OpenAPI, allowing you to create GraphQL APIs from OpenAPI specifications.

Pathfinder is a tool in Graphbase that allows you to run and explore GraphQL queries. It works with any GraphQL API, providing a similar experience to GraphiQL.

Graphbase allows you to add API security by using providers like Auth0 or custom JWT tokens. It checks the validity of the token before processing the request, ensuring secure access to your GraphQL API.

Yes, Graphbase is open source. The Graphbase engine is built with Rust, packaged as WebAssembly, and can be deployed to Cloudflare or Deno deploy. You can also host it yourself if you prefer.

A GraphQL resolver in Graphbase is a function that handles the logic for fetching or manipulating data for a specific field in a GraphQL query. You can extend existing GraphQL APIs by adding custom resolvers to fetch additional data or perform custom logic.

Graphbase focuses on providing a seamless local development experience without the need for extensive setup. It automatically generates GraphQL schemas from your data sources, supports edge caching, and offers easy deployment options, making it more developer-friendly compared to other platforms like Hasura.

Jamie Barton
Jamie Barton
55 min
10 Nov, 2023

Comments

Sign in or register to post your comment.
  • Nikhita Sareen
    Nikhita Sareen
    none
    Is anybody able to join?
  • Lucas Estevão
    Lucas Estevão
    Avenue Code
    It should start at 9 a.m. PST, I guess there was a confusion because of time changes in the US.
  • Nelly Ruehl
    Nelly Ruehl
    JPMorgan Chase
    Is this still happening? Zoom says "waiting for the host to start the meeting".
Video Summary and Transcription
In this Workshop, we explore GraphBase and GraphQL, focusing on using Neon as a connector and Postgres as a database. We learn how to set up Neon and the Postgres connector, automatically generate a GraphQL schema, and create a GraphQL API with Neon. We also delve into edge caching, extending GraphQL APIs, and integrating with MongoDB, Contentful, and other data services. Additionally, we cover adding API rules and security with Click as the auth provider.

1. Introduction to Graphbase and GraphQL

Short description:

In this part, we will explore Graphbase and GraphQL. We'll discuss the challenges of using multiple tools and services in the ecosystem and how GraphQL can provide a unified API. We'll also address the issue of data latency and introduce GraphQL edge caching. Additionally, we'll focus on using a Postgres database with NEON as a connector and demonstrate how to deploy globally using CloudFlare workers.

Hey, everyone. Thanks very much for taking the time today to join me, and we're going to be spending some time today looking at Graphbase and GraphQL. This isn't a workshop people to GraphQL, but I'm more than happy to answer any questions that anyone has there. So, hey, Natasha and everyone else that's in the chat, great to have you all. And please, feel free to interrupt me at any point.

The style that I'm going to go for today actually is going to be me just showing you a few things. And if you have access to GetNation portal, there is other workshops and videos on there from myself about this very topic. But I think today we can go through and show various parts. And I want to talk specifically about one way that you can build GraphQL APIs on top of a Postgres database with a new connector that we have. So that could be interesting. And we'll kind of take a tour of the product and what it enables developers to do. And hopefully, that's enough to, you know, inspire some questions and, you know, invite you to try it out.

I'm just going to flip through some slides to begin with, just to set the scene. And like I said, please ask any questions, should you have them. But I want to talk to you about GraphQL and how you can make your data fast. I'm Jamie. I've been doing GraphQL for about five close years now. I do have a website, GraphQLWTF, where I release weekly videos. That's currently on pause, but I will be resuming weekly videos on that at the moment. There's a huge back catalog if you're interested. You can follow me on Twitter, whatever it's called today. My handle is just Barton Backwards, which is no trab.

The biggest problem that I think we see today, or certainly the problem that I've experienced personally, is we have so many different tools in the ecosystem, and all of these tools allow us to do so many great things. Even my own website has tools for sending notifications via email, via Slack, pulling in content from a CMS, pulling in content from a digital asset management platform to get my images and videos, and certainly from my GraphQL website, content comes from a lot of different places. Which is great. I use these kind of best of breed services, as the industry calls them. But we often spend so much time figuring out how each of these APIs work. We spend so long reading each documentation or SDK reference to really figure out how everything works together, and by the end of it we've got a package json file that's got a dozen or if not multiple gigabytes worth of Node modules just to install SDKs and whatever, and that's okay. But I don't think it's the best experience, and I think GraphQL actually shines here because it allows us to interface with all of these different services as one API. And the other issue that I think we have is, all of these different services belong somewhere, the data is stored somewhere, and it's accessible. If I'm here in the UK and I'm wanting to access data that's on US East one or whatever, I have to make a request, get that data and the latency there can add up, right? And that latency is replicated for each individual service that I use, which isn't great either. Now, a lot of the different service providers that we use do allow you to replicate data or whatever, but you often have to pay a per provider a cost to replicate. So that's not great, you have all of these different costs associated with just one output because you've had to replicate content around the world. So that's not an amazing experience, at Graphbase, we are trying to resolve that by something that we call GraphQL edge caching. So we're able to put a layer in front of your data sources so when someone requests that, we cache that and response times go from looking something like this to the green line. Anything you request comes through a lot quicker. So how do we go about connecting stuff? Well, this is three ways that I want to show you and I'm not going to be focusing on these too much today, the postgres one is the one that about. We have three connectors here. MongoDB and an open API connector. The open API connector is pretty cool because that can take an open API specification and you can use that spec and the great thing about specs is they follow a specification so we're able to determine what fields are and end points are and what arguments they take because these specifications follow a spec and the schema follows a spec. So, we're able to automatically create a GraphQL API based off the open API spec, which is pretty cool. And because it's GraphQL, we can introspect that in the same way. We can introspect GraphQL APIs and we can generate something that you can use. MongoDB, on the other hand, here we have a way to define models and specify fields on those models and kind of add some strictness to our MongoDB, which is traditionally a document database. We can add some kind of rules and behaviors around how documents are stored and we generate all the APIs for that. But the one that I want to focus on today is using a Postgres database and we'll be using NEON, so please go to NEON dot tech and sign up and create your own database there if you want to follow along. But here we're able to kind of plug in NEON as a connector, add it to our schema as a data source, then we're able to add caching to that so when we make a request it fetches data from the cache and not from NEON. Then once we've got all of our connections and data sources lined up all we then need to do to deploy this to the edge globally around the world, over 200 points of presence, is run an npx craftbase deploy and that will deploy around the world which is pretty cool. Everything's built with Rust and it is then packaged up using WebAssembly and deployed into different, not lambdas, but CloudFlare workers that's deployed, like I say, around the world on the CloudFlare Edge network. Everything I'm going to show you and talk about today is open source, please check that out if you're interested.

2. GraphBase, Neon, and Postgres Adapter

Short description:

Once we've deployed everything globally, we need to understand how to query it. Neon provides a dashboard and database that allows us to form GraphQL queries. We can create things with mutations and fetch things with queries, including pagination arguments. pathfinder.dev is a tool to run GraphQL queries. GraphBase aims to solve the problem of consuming data from different services by providing a unified GraphQL API. It also offers automatic deployment of API versions when changes are made to the database. Today, we will focus on Neon and the Postgres adapter. We'll explore the hosted version briefly, but most of our work will be done locally. GraphBase deploys GraphQL endpoints around the world, utilizing edge-caching and features like KVStorage to reduce latency. Each change to the schema is logged, and specific deployments can be accessed for different branches or features.

But once we've got everything kind of deployed around the world we then need to figure out how do we query this, what does that look like? Well, here we can see in the background is a screenshot of Neon. I'm going to dive into this in about two or three minutes time. And we're going to look at that dashboard and database and more tables and data we've got. But that database we're able to form GraphQL queries from. We can see on the screen here we've got a mutation to create things. Then we've got a query to fetch things. And we can see we've got some pagination arguments in here to fetch the first or last or whatever nodes we want from the database. And all of that is generated automatically, which is pretty cool. And yeah, lastly, pathfinder.dev is a way to run these GraphQL queries. This doesn't just work with Graphbase, but it works with any GraphQL API. It's a way to view and perform GraphQL requests similar to GraphiQL, if you've used that before. And that's what we have on the local experience and the deployed versions of Graphbase.

So I think that probably is a good transition to talk about Graphbase very, very quickly. Kind of give me the reasons why we created Graphbase and what we're looking to solve. But just as a high-level overview, GraphQL here, we've got a query to fetch a product by a slug. And the idea, the things that we can make really nice and intuitive for you as a developer is, you could have all of your different data sources, like I mentioned before, spread across different services. And if you want to create one query to fulfill this card requirement here, we can get the image, the title, the price, the variance, whatever, from all the different services that are managing that. So we've been told over the last few years it's important that we have different services to do their own individual things. But actually consuming all of that is actually a problem that we created because of that. And GraphQL is a really cool way to solve that. So, yeah, what GraphBase will do is, we will give you an API to call this GraphQL query. We will deploy that. Whenever you create a pull request on your work and you make any changes to your database, we'll deploy a different version of that as well, which is cool. Cool. So, yeah. Hello, and welcome to anyone that is just joining. It's great to have you all here. And like I said, please let me know if you've got any questions.

So, now we've set the scene. We've talked about the issues and problems that we have and why we create a GraphBase. For anyone just joining, we're looking to solve these two things here. Lots of different data sources with a different learning curve for every single tool that we use and the issue where all of this stuff is deployed around the world and it costs so much because we have to replicate that for each individual service. We think we can bring all of that under one GraphQL API. And today, I want to spend some time talking about Neon and the Postgres adapter that we've just created. So, Graphis, when you sign in, if you go there now and you get started in creating accounts, I'll sign into mine and show you around very briefly what the hosted version looks like. But everything we're going to do today is pretty much going to be something that we work on locally. So here, we've got a few different projects. If I just go to this project here, we can see here, this is our dashboard, we've got our GraphQL endpoints. And these are the endpoints we tell Netlify, Versaille, Fly, wherever you deploy this, this is my GraphQL endpoint. And that endpoint is distributed around the world, deployed to the edge, and has all of that kind of edge-caching stuff built alongside it. We've got things like KVStorage, which you can access all at the edge as well. The idea is to reduce that latency as much as much as we can. So this is a project that gets hammered quite a bit from some kind of tool that compares different edge deployments, but it's kind of good enough to show you around. So here we've got all the deployments that every single time you make a change to the schema, the schema is something I'll show you shortly, but every single change you make, you can go in and see, I added this, I removed this, I added this field, I added this connector. You can see exactly what went on and they build logs for that as well. And you can see exactly who did that. You've got access to the individual endpoints for that specific deployment as well. So if you create a branch to add a new feature or whatever, you get a specific deployment for that GraphQL API. And that's a pain that like setting that stuff up manually. If you're not using something like GraphBase, it's a bit of a pain.

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.
End-To-End Type Safety with React, GraphQL & Prisma
React Advanced 2022React Advanced 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
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.
Get rid of your API schemas with tRPC
React Day Berlin 2022React Day Berlin 2022
29 min
Get rid of your API schemas with tRPC
Today's Talk introduces TRPC, a library that eliminates the need for code generation and provides type safety and better collaboration between front-end and back-end. TRPC is demonstrated in a Next JS application integrated with Prisma, allowing for easy implementation and interaction with the database. The library allows for seamless usage in the client, with automatic procedure renaming and the ability to call methods without generating types. TRPC's client-server interaction is based on HTTP requests and allows for easy debugging and tracing. The library also provides runtime type check and validation using Zod.
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.