Build and Deploy a GraphQL API to the Edge with MySQL and PlanetScale — Part 1
Set up Grafbase
This series is perfect for anyone looking to remove the bloat from their GraphQL backends and switch to a fully managed deployment platform with support preview environments, instant GraphQL APIs, and more.
In this 11-part series, we will build a GraphQL API with Grafbase, and persist data to a MySQL database managed by PlanetScale.
Here's a breakdown of what we'll be building:
This is part 1
Grafbase
Grafbase simplifies the process of creating and implementing your personalized GraphQL API at the edge while ensuring complete end-to-end type safety.
By using resolvers and connectors, Grafbase allows seamless integration with any data source. Additionally, you can take advantage of features such as edge caching, authentication and permission rules configuration, serverless search functionality, and more.
Grafbase's versatility extends to local development as well, thanks to the Grafbase CLI. Each Git branch has its preview deployment, facilitating convenient testing and collaboration.
PlanetScale
PlanetScale simplifies database management and scaling. It ensures high availability, seamless replication, and effortless deployment across multiple regions.
With features like automatic sharding, intelligent load balancing, and instant schema changes, PlanetScale simplifies integration and offers robust security measures, including end-to-end encryption and comprehensive access controls.
From startups to enterprises, PlanetScale provides a reliable and scalable solution for managing databases, allowing you to focus on building innovative applications and services.
1. Set up Grafbase
Let's begin by creating a new Grafbase project. If you have an existing frontend application that you want to create a GraphQL API, you must run that inside of that project's root directory.
npx grafbase init graphql-mysql-api
This command will ask whether you want to create a Grafbase project using GraphQL SDL or TypeScript as its configuration type.
We'll next install the graphql
dependency so we can adequately throw GraphQLError
's inside resolvers later on.
cd graphql-mysql-api
npm install graphql
That's it! You now have a Grafbase project set up and ready to use.