Before we start creating our app, we first need to create an API connected to a database. For this purpose, we will use a free tool called Supabase.
Go to supabase.com and Sign up to create a new account.
Next, we need to create a new project. Click the "New Project" button once you login into the Supabase app, and follow the wizard to create your API project.
Now we need to create our database table to store our to-do tasks.
Start by clicking the Table Editor button on the left sidebar menu. Once you're on this page, press the "Create a new table" button.
When the form opens, add the following columns to match the screenshot below:
id (uuid)
title (varchar)
description (text)
completed (bool)
created_at (timestamptz)
Make sure "Enable Row Level Security" is NOT checked.
Since we are going to be building our app on top of GraphQL query language, we need to tell Supabase to build its schema.
On the left sidebar menu click the "SQL Editor" button. Once on this screen, press the "+ New Query" button.
Now enter the following code snippet in the editor and press "RUN"
Go to Settings => API
page. Here you can find the API URL and Key as shown in the screenshot below.
That's all. We're done with creating our API for the project. All we need to do is consume it now.
The last step is to generate typescript interfaces from our GraphQL schema. This step is used to enhance the developer experience to strongly type our API.
Install the following dev dependencies:
Add the following script to the script section of your package.json file:
Create a file codegen.yml
in the root directory:
Replace [[API_URL]]
and [[API_KEY]]
with the values relevant to your project.
To consume our GraphQL API on the app, we will be using the popular Graphql Client. Luckily, we already have an Apollo plugin available for BlueBase that takes care of all the setup.
Same as the last time, we import the apollo plugin:
Create the following file in the root folder:
Replace [[API_URL]]
and [[API_KEY]]
with the values relevant to your project.
Similar to how we use the plugins, we need to pass our configs object as a prop to the BlueBaseApp
component.
Change the contents of the App.tsx
to match below:
This is it. Our App is configured to use the GraphQL API through the Apollo client.
Now we need to input our API URL as well as the API Token into the Apollo client. We do this by using .
At the time of writing this tutorial, the latest version of Apollo Client (v3.5.4) has compatibility an with react-native. Add the following file in the root folder to bypass it.