Graphweaver Docs
  • Home
  • Github
Get Started 🚀
🪶

Connect to SQLite

  • Prerequisites for Connecting Graphweaver with SQLite
  • Step 1: Creating a Database
  • Step 2: Setting up the Graphweaver Project
  • Step 3: Installing the Required Packages
  • Step 4: Configuring the Connection to SQLite in Graphweaver
  • Step 5: Making our first GraphQL Query

Prerequisites for Connecting Graphweaver with SQLite

In this guide, we are going to cover how to get Graphweaver and SQLite connected.

Before we dive in, let’s make sure that you have Node.js version 18 or greater, and pnpm version 8 or greater installed on your local machine.

Once these are installed, we can get started.

Step 1: Creating a Database

For this we will use the Chinook Sqlite database. The Chinook database is an alternative to the Northwind database (popular with Microsoft systems) and gives us a good dataset to test from. The database consists of Albums, artists, tracks and Customers.

đź’ˇ
If you have your own SQLite database, then you can use that instead

The SQLite database can be found at the link below. Let’s start by downloading a copy:

https://github.com/lerocha/chinook-database/blob/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite

Once you have the database, we can start a new Graphweaver app project.

Step 2: Setting up the Graphweaver Project

Now we are ready to install Graphweaver on your local machine. To do that, run the following command:

npx graphweaver@latest init

This will start the creation wizard that will guide you through creating your Graphweaver app.

Give your app a name. Here, we are calling it sqlite-example :

? What would your like to call your new project? sqlite-example

Next, select that you would like to use SQLite:

? Which Graphweaver backends will you need? (Press <space> to select, <a> to toggle all, <i> to invert selection, and <enter> to proceed)
❯◉ MikroORM - SQLite Backend

You will be asked if you are happy with a new directory being created for your new app. Hit enter.

Step 3: Installing the Required Packages

Now that we have the project created, make sure that you change directory and install the dependencies.

cd sqlite-example
pnpm i

Then run pnpm start - you should now be able to see the Admin UI interface at http://localhost:9000:

image

There are currently no data sources attached to Graphweaver, so let’s go ahead and do that next.

Step 4: Configuring the Connection to SQLite in Graphweaver

In this next step we are going to create the connection from SQLite to Graphweaver. For this we can use the CLI tool to import the database. First make sure that you copy the Chinook_Sqlite.sqlite into the root of the project then run the following command:

npx graphweaver@latest import sqlite --database=Chinook_Sqlite.sqlite

The CLI Introspection will create the files in your project to model the data:

â ™ Introspecting...Fetching database schema...
â ą Introspecting...Building metadata...
Closing database connection...
Database connection closed.
Import complete.

We now have everything we need to start the server and make our first GraphQL request.

Let’s do that next.

Step 5: Making our first GraphQL Query

Back on the command line, start the server with pnpm start. This will start the server at http://localhost:9000 - you should now see your data source, listed like this:

image

Click on the Open Playground button to open the playground, where you can now send a query to the GraphQL server:

query {
  result: albums(pagination: {offset: 0, limit: 50, orderBy: {id: ASC}}) {
    id
    title
    __typename
  }
}

And get the results:

image

Congratulations! You have now connected SQLite to Graphweaver, and you can keep creating your tables and data models.

The great thing about Graphweaver is that you can connect multiple datasources together. For more information on what data sources you can connect, take a look at the Introduction to Data Providers page.

Made with đź’ś in Australia

Exogee