Build multi-tenant RAG with Neon's database-per-user model — no nosy neighbors, max isolation, minimal costs

Use Exograph with Neon

Build GraphQL backends in minutes with Exograph and Neon

This guide was contributed by the Exograph team

Exograph is a new approach to building GraphQL backends. With it, you can effortlessly create flexible, secure, high-performing GraphQL backends in minutes. Powered by a Rust-based runtime, Exograph ensures fast startup times, efficient execution, and minimal memory consumption. Exograph comes equipped with a comprehensive set of tools designed to support every stage of the development lifecycle: from initial development to deployment to ongoing maintenance.

Exograph supports Postgres for data persistence, which makes it a great fit to use with Neon.

Prerequisites

Create a backend with Exograph

Let's create a starter project with Exograph. Run the following commands:

exo new todo
cd todo

You can check the code it created by examining the src/index.exo file (which has a definition for the Todo type). If you would like, you can try the yolo mode by trying the exo yolo command.

Next, let's set up the Neon database.

Create the schema in Neon

  1. Navigate to the Neon Console, select your project, and copy the connection string, which will look something like this: postgresql://alex:AbC123dEf@ep-cool-darkness-123456.us-east-2.aws.neon.tech/dbname.
  2. Create schema in Neon using Exograph CLI:
exo schema create | psql <the connection string>

Launch the backend

EXO_POSTGRES_URL=<the connection string> exo dev

It will print the necessary information for connecting to the backend.

Starting server in development mode...
Watching the src directory for changes...

Verifying new model...
Started server on 0.0.0.0:9876 in 717.19 ms
- Playground hosted at:
 http://0.0.0.0:9876/playground
- Endpoint hosted at:
 http://0.0.0.0:9876/graphql

That's it! You can now open http://localhost:9876/playground in your browser to see the GraphQL Playground.

You can create a todo by running the following mutation:

mutation {
  createTodo(data: { title: "Set up Exograph with Neon", completed: true }) {
    id
  }
}

To get all todos, try the following query:

query {
  todos {
    id
    title
    completed
  }
}

And you should see the todo you just added. Please follow Exograph's guide to creating a simple application for more details.

Learn more

In this guide, we have created a basic todo backend using Exograph and Neon. You can extend this further by establishing relationships between types, implementing access control rules, and integrating custom business logic. Check out Exograph's application tutorial for more details.

To deploy Exograph in the cloud and connect it to Neon, follow the guide below (select the "External Database" tab for Neon-specific instructions in each case):

  1. Deploying on Fly.io (these instructions can be adapted to other cloud providers)
  2. Deploying on AWS Lambda

Last updated on

Was this page helpful?