Instant Serverless GraphQL Backends

Rate this content
Bookmark

Grafbase is a data platform for developers that lets you build and deploy GraphQL backends with a top-notch developer experience.

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

FAQ

In the Schema 1st approach, you can build and deploy a backend solely by writing your GraphQL SDL. GraphBase takes care of the rest once connected to GitHub.

You can initialize a new GraphBase project in the root of your Next.js application using the command `mpx graphbase init`.

GraphBase allows you to define models using GraphQL SDL, use custom directives like `@unique` and `URL`, add relations between models, and automatically generate an API to create, update, delete, and read data.

You can run a local GraphBase API using the command `mpx graphbase dev`, which runs on localhost:4000.

GraphBase uses the `@unique` directive to ensure that fields marked as unique cannot have duplicate values, preventing the creation of duplicate entries.

Yes, GraphBase can be integrated with GitHub. You can sign in to GraphBase using your GitHub account, connect to your repository, and create a new project.

GraphBase's unique preview environment allows you to work with data scoped only to a specific branch, ensuring that production data is not affected. This is useful for testing new features before merging them into the main branch.

GraphBase supports authentication and authorization features including JWTs, OpenID Connect providers, and integration with user-management software like Clerk.

You can create a Clerk project, set up authentication types, create a JWT template for GraphBase, install necessary dependencies like Apollo Client, and configure environment variables to allow communication between Clerk and GraphBase.

GraphBase allows you to configure permissions and use custom directives to control operations like CREATE, READ, UPDATE, and DELETE. You can also integrate user authentication to validate requests securely.

Jamie Barton
Jamie Barton
8 min
08 Dec, 2022

Comments

Sign in or register to post your comment.
Video Summary and Transcription
In the Schema 1st approach, you can build and deploy a backend only by writing your GraphQL SDL. Connect this to GitHub, and GraphBase takes care of the rest. Once the code is deployed, sign in to GraphBase using your GitHub account and explore the dashboard, schema, and playground. GraphBase offers authentication, authorization, permissions, and custom directives. Connect GraphBase to user-management software and create sign-in and sign-up pages.

1. Introduction to GraphBase and Backend Development

Short description:

In the Schema 1st approach, you can build and deploy a backend only by writing your GraphQL SDL. Connect this to GitHub, and GraphBase takes care of the rest. We can define models using GraphQL SDL, add relations between them, and run a local GraphBase API. The API allows us to create, update, delete, and read data. We can also fetch related data using pagination and retrieve singular records using unique fields. Finally, we can push our code to GitHub.

♪♪♪ So, in the Schema 1st approach, you can build and deploy a backend only by writing your GraphQL SDL. Connect this to GitHub, and GraphBase takes care of the rest. There are so many different features that I encourage you to go and check out, but in this video, we'll explore some of them. And, at the end, we'll use a user management platform to authorize requests to our GraphBase backend. There are many other things that we're working on at GraphBase, and we'll soon allow you to bring in other data sources to work with your backend.

So, let's dive on in. Here I have a Next.js application. I'm going to use the mpx command to initialize a new GraphBase project in the root of my Next.js project. So this shows how you can add GraphBase as a backend to your existing project. Here we can define all of our models using GraphQL SDL. We use the custom directive model to tell GraphBase to generate an API for us, and then we can use the scalar types and other directives such as unique here, and in this case, for the URL of a post, we can use an opt-in to further validation with the URL scalar. We can then go on to add relations between our models, and then we can run the mpx graphbase dev command to run a local GraphBase API on localhost 4000. If we open this up, and we have a look at the schema and the documentation, we can see all of this was automatically generated for us from the GraphBase CLI. And all of this works locally, and it gives you an API to create, update, delete, and read data. So in the case here, we are creating a new post, we can provide a custom URL and we can get that data back. If we try to create this again, we can see here that the URL directive and the at-unique directive have kicked in. We're not able to create a duplicate post with that same URL because we said it was unique.

Now, let's go on to create another post and this time we'll create an inline comment as a relation when we create a new post. So here, we'll give it some text and we'll submit that mutation. Next, let's create a new comment, but this time we'll take the ID from an existing post and we'll now link this comment when we create it. Now let's have a look at fetching all of our posts using the collection query. We can opt in to using the pagination and for each of our nodes, we can get the fields that we like. We can take this a step further by fetching the related comments of a post, which also supports pagination. Finally, we can retrieve singular records for our data in our backend by using the ID or any unique field. Let's take the ID of one of our posts and we'll now use the mutation to update. We can update using the ID or again, using that unique field. And here we can provide a new title value for this post. Now if we update our query when fetching all of our posts, and we get the ID of a comment, we can now use the mutation that's generated automatically to delete one of our comments. So we can provide either the comment ID or if we had any unique fields, we could provide that inside of the arguments. Next, let's create a GitHub repository and push all of our code to GitHub.

2. GraphBase Deployment and Backend Features

Short description:

Once the code is deployed to GitHub, sign in to GraphBase using your GitHub account. Search for the repository, connect, and create a new project. Explore the dashboard, schema, and playground. Add the ability for users to vote on posts. Update the UI and backend in a branch. Open a pull request to deploy a preview environment. Merge and approve the pull request to deploy to the edge. GraphBase offers authentication, authorization, permissions, and custom directives. Connect GraphBase to user-management software. Create a project with Clerk, configure authentication, and install dependencies. Create sign-in and sign-up pages. Configure environment variables. Run the local CLI and Next.js application. Create a query to the GraphBase backend. Validate authorization header. Update the schema and observe the error. Choose GraphBase as your next backend. Join the private beta at graphbase.com.

Once we've deployed the code to GitHub, we can then sign in to GraphBase using our GitHub account. Then we can search for our repository and we can connect and create a new project on GraphBase. And this wouldn't be a SaaS app if there wasn't confetti! We can then explore the dashboard inside of GraphBase to explore the current schema and the playground where we can create and update data that's happening at the Edge.

Now let's imagine we want to add the ability for users to vote on certain posts. Well, I could update the UI and the back end at the same time in a branch. Then I can commit all of this code to GitHub and open a pull request and automatically GraphBase will deploy a unique preview environment for that specific branch. So here I can work with data that's scoped only to that branch so I'm not affecting anything that is in production and I can safely work and show all of my colleagues to make sure that the voting functionality works as we expect. So here we can see we are querying and mutating some data inside of our back end that is in that isolated branch.

Then once the team's happy, all we need to do is merge and approve that pull request and GraphBase will take care of deploying this to the edge. GraphBase also comes packed with many other features, things including authentication, authorization, permissions, and custom directives for trailing any updates to queries using the new live directive. You can connect GraphBase to almost any user-management software using JWTs or any OpenID Connect providers to automatically handle and authorize requests sent by users or groups of users. So let's check that out. Let's create a project with Clerk. We'll give it a name of GraphQL Galaxy. We'll allow passwords for our authentication type and we'll create the project. Now that's created, we'll create a JWT template for GraphBase. And here we can configure many things, including the group-based authentication strategy. Let's install a few dependencies, including Apollo Client, so we can make a request from our index page on our application. And we'll configure the Clerk provider using the Next.js hooks.

Now we'll create our pages for sign-in and sign-up for accounts with Clerk. Thankfully, Clerk takes care of all of this by providing ready-to-go and ready-to-use components that we can embed inside of our application. Now that we've added those, we can just configure a few more things, including our environment variables, so our front-end knows how to communicate with Clerk and GraphBase. Let's run both our local CLI with GraphBaseDev and our Next.js application. We'll create a new account with our email, and then we can update our index page to create a query that calls to our GraphBase backend. If we head to the index page, we should see that the query is running successfully because we are signed in, and we are sending a valid authorization header. This token is generated from Clerk, passed to GraphBase, and validated. But, if we update our schema now to only allow the DELETE operation, if we go back to our application and try to run the query to fetch all of our posts, we now should see that there is an error. If we inspect this error and have a look into why, we should see that the operation for the LIST type is no longer valid. Hopefully this very quick video has given you an idea on what backend to use for your next project. Check out graphbase.com where you can join the private beta for free today.

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.

Workshops on related 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