Need help with rust-graphql-juniper-actix-diesel-postgres?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

197 Stars 23 Forks 33 Commits 1 Opened issues


An example GraphQL server written in Rust

Services available


Need anything else?

Contributors list

# 15,524
32 commits

Rust + GraphQL + Juniper + Diesel + Postgres + Actix

Yes, I know that this is a borderline absurd web stack for the ubiquitous TODO application but I had a lot of trouble getting this all to work. I started using these things for a more ambitious project and I'd love to spare you the trouble. So here's some basic boilerplate to get you up and running.


Here's what does what:


Web server actix-web
Database PostgreSQL
SQL engine Diesel
GraphQL library Juniper
GraphQL UI GraphQL Playground

Run locally

Before you get started, make sure that you have PostgreSQL, Rust, Cargo, and the Diesel CLI installed and that you have Postgres running somewhere.

# Fetch the repo
git clone
cd rust-actix-diesel-postgres-juniper

Set up the database

cp .env.example .env # Modify this file to match your Postgres installation

diesel setup diesel migration run

cargo run # could take a while!


can be any Postgres installation. For my purposes, I have it set to

Once the server is running, you can access the GraphQL Playground UI at http://localhost:4000/graphql.


The server implements the following GraphQL schema:

type Todo {
  id: ID!
  task: String!
  done: Boolean!

input CreateTodoInput { task: String! done: Boolean }

type Query { allTodos: [Todo!]! getTodoById(id: Int): Todo }

type Mutation { createTodo(input: CreateTodoInput): Todo markTodoAsDone(id: Int): Todo markTodoAsNotDone(id: Int): Todo }

schema { Query Mutation }

Tour of the codebase


What it provides
The GraphQL context that handles query execution

struct and some helper functions encapsulate the Diesel-powered Postgres querying logic
The connection pool that handles the Postgres connection
HTTP endpoint that makes GraphQL and the GraphQL Playground work
, and
objects that undergird the GraphQL interface
Just the standard
Actix HTTP server setup
All of the data types used for querying Postgres and providing GraphQL results
The Diesel-generated table schema

Future TODOs

Get it? Anyway, here's some areas for improvement (pull requests very much welcome):

  • Error handling — Right now errors basically propagate directly from Diesel/Postgres into the GraphQL JSON output, which is subpar. If any of you can point me to good educational resources on this, please file an issue!
  • Better execution engine — The server uses the extremely powerful actix-web but the actual DB interactions don't use Actix actors and it'd take this setup to the next level if they did.
  • Use macros for schema generation — The powerful
    macro could help reduce boilerplate and improve development velocity.


I'm basically a beginner with Rust and would not have been able to put this together without peeking long and hard at the example projects and blog posts listed below. The lower-level bits you see here are basically stolen from BrendanBall. All that I've added is the

data construct for executing queries.

Example projects

Blog posts

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.