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 TypeScript Congress 2023, check out the latest edition of this JavaScript Conference.

FAQ

GraphBase improves the developer experience by offering a unified GraphQL API that connects various data sources, including REST APIs, GraphQL APIs, and databases. This eliminates the need to learn different SDKs and API documentations, making it easier to integrate and manage multiple services.

GraphBase supports various connectors, including GraphQL connectors, OpenAPI connectors, and database connectors like MongoDB. Upcoming support includes Postgres and Neon connectors. These connectors allow users to integrate different types of data sources seamlessly into a single GraphQL API.

You can extend a GraphQL API using GraphBase by defining new fields and resolvers in your schema. For example, you can extend a type with a new field and provide a resolver that fetches data from another API or performs custom logic. This allows you to add custom functionality to existing data sources.

GraphBase handles caching by allowing you to define caching rules in your configuration. You can specify cache duration, stale-while-revalidate behavior, and caching scopes (public or API key-based). Caching responses at the edge significantly improves performance and reduces the load on the underlying data sources.

Examples of data sources that can be connected to GraphBase include Contentful (a headless CMS), Stripe (a payment API), and MongoDB (a database). GraphBase can integrate both REST and GraphQL APIs, as well as databases, to provide a unified GraphQL API.

You can deploy a GraphQL API using GraphBase by running the command 'npx graphbase dev' in your terminal. This will start a local server for development. When you are ready to deploy to production, you can connect your project to a GitHub repository and deploy it using GraphBase's deployment tools.

Yes, GraphBase supports custom authentication methods. You can use JWT tokens from existing authentication providers like Auth0 or Clerk to secure your GraphQL API. GraphBase allows you to configure authorization rules and forward authentication headers to the underlying data sources.

Yes, GraphBase can transform REST APIs into GraphQL using the OpenAPI connector. By providing the OpenAPI specification, GraphBase can automatically generate GraphQL queries and mutations for the REST API, making it easier to work with RESTful services in a GraphQL environment.

GraphBase currently supports JavaScript and TypeScript for writing resolvers. The system takes care of compiling the code, so you don't need to create any build scripts. Future support for other languages like PHP and Rust is also planned.

GraphBase aims to solve the issue of slow response times and high costs associated with connecting to multiple data sources and APIs spread across different regions. By providing a GraphQL API at the edge around the world, GraphBase ensures fast response times, typically under 50 milliseconds, without requiring users to pay extra for regional flexibility.

Jamie Barton
Jamie Barton
67 min
05 Oct, 2023

Comments

Sign in or register to post your comment.
Video Summary and Transcription
GraphBase is a platform that provides a GraphQL API for different data sources. The Workshop covers connecting to APIs, creating a new project, and building a GraphQL backend. It also explores extending APIs, transforming with Open API spec, using database adapters, and securing GraphQL queries. Caching and query scope are discussed, as well as data availability, cost, and authentication configuration.

1. Introduction to GraphBase

Short description:

React-JS for Webinar Thank you very much. Great to be here. Today's world of different APIs that we have. So that's what we are trying to resolve at GraphBase. By default, we put the GraphQL API for all of your different data sources at the edge around the world at over 300 locations. So your user, when they make a request, are most likely going to get a response that comes back in sub 50 milliseconds.

React-JS for Webinar Thank you very much. Great to be here. I think I'm all set up, I was connecting a few displays to help us get going today.

So this first slide I opened up talking about today's world of different APIs that we have. We have so many different SDKs and APIs that honestly, the documentation for all of these varies so much, the player, the developer experience, all of those are very, very different. And these are just a few of the logos I think that for a few of the products that we use today, from databases, to CMSs, to content management systems, to commerce APIs, there is so much. And yeah, we spent so long kind of connecting all of these things and learning the different SDKs and APIs that it's not the best experience. I don't think. And the other thing as well, closely attached to this is that those data sources are often at one region. And if in a very big if, the preventer that you're using gives you the flexibility to push this, push whatever service you've got to different regions around the world, you often have to pay for that flexibility. And the more services you've got and the more regions you want to be in, the more that's going to cost you, and that is not a great place to be in. So that's what we are trying to resolve at GraphBase. Here we are a GraphQL company, and we want to solve this issue. So at a very high level, when you're using something like GraphBase, you get really, really fast response times instead of going back to the different regions. By default, we put the GraphQL API for all of your different data sources at the edge around the world at over 300 locations. So your user, when they make a request, are most likely going to get a response that comes back in sub 50 milliseconds.

2. Connecting to APIs and Creating a New Project

Short description:

In this workshop, we will cover connecting to existing APIs, including GraphQL, OpenAPI, MongoDB, and potentially Postgres. We will also explore deployment options and making queries to different APIs. To begin, we will create a new project using NPX Graphbase Init, providing a project name and selecting TypeScript as the configuration. Once the project is set up, we can focus on the server element and start building our GraphQL backend. The project will include a Graphbase folder and a package JSON file.

So the first thing that I think that I want to cover in today's workshop is connecting to an existing API. If there is any API that you use now, feel free to leave a comment in the chat about whatever APIs that you're using and we can look to connect some of those. Feel free to follow along as I do and use your own APIs. If you want to use the APIs that I use, obviously, they'll be on screen and I can share those in the chat as well.

The first thing that we'll do in the workshop is we'll connect to our data sources and connecting to the different data sources looks a little something like this. This is not in the code just yet, but this is what we'll be doing in a few minutes. We will be using the GraphQL connector. We'll also be using the OpenAPI connector and we'll also be looking very briefly at the MongoDB connector. If we get time, I'll show you the Postgres connector as well that we've got coming out in a few weeks.

Once we've done the connection side of things, we can actually go on to deploy that using the command line or we can connect to GitHub repository and we can deploy this. I think for today's workshop, we can focus mostly on the local environment. I want to show how easy it is to build GraphQL APIs locally without having to deploy. But once you do want to deploy and you want to make this available for your applications, all you need to do is run mpx graph-based dev. It will ask you to log in, obviously, if you haven't done that before. And then yeah, you can deploy it. And what we do under the hood is everything is deployed to the edge and we use the whole thing is written in. Whoops. What's happened there? There we go. So everything is written in Rust, the whole graph-based engines written in Rust. And then we package that up using WebAssembly and we deploy that artifact around the world to, we use Cloudflare, so we deploy it to the Cloudflare network, which is pretty cool. All right. And then lastly, we'll explore making different queries to all of these APIs. Some are GraphQL API, some are MongoDB, and some are REST APIs, believe it or not. There is a tool, pathfinder.dev, that you can use to follow along to make queries. We'll be using the version that's hosted with the CLI, but if you want to use any GraphQL API and perform operations, we have this cool tool. And this is an overview of everything that we'll look at today. So I think we are ready to dive into everything. So if there are any questions, please let me know. But first and foremost, I think we just kick things off. I'm just opening Discord as well, so if anyone does have any questions, please let me know. And please ping me in the chat as well.

Okay, so let's begin by creating a new project. We'll bump the font up here so we can see what's going on. And then here we can use NPX Graphbase Init. Obviously, if you have NPM installed, you'll be able to run this. And then all you need to do is give a name for your project. Now, if you have an existing project, say it's an Astro app, say it's a View app, a React app, an Angular app, whatever kind of application, maybe it's a mobile application with something like one of the mobile frameworks, you can use that. You can use Graphbase inside of that as well. So wherever your project is, if you have something already, change directory into that now inside of the terminal. And then proceed to run NPX Graphbase Init. Because I'm not inside of an existing project today, I'm just creating a GraphQL backend from scratch with outside of a frontend. We're just going to be focused on the server element here. I'm going to give my project a name. So I'm just going to call this TS Workshop. And then what this is then going to do is it's going to ask me what type of configuration would I like to use to scaffold and build and configure my Graphbase backend. I like TypeScript, so I'm going to choose that and it feels very fitting given this is TS Congress. And then once that's done, we will then get a folder with a file in for our configuration. So if we change directory into that TS Workshop now and I'm going to open this up inside of my code editor. If we have a look and see what it's given us, we can see that we have a folder called Graphbase. We have a package JSON, which has some data in here.

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.
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.