Scratch-Containerised Rust GraphQL-API using Dataloaders

Overview

Dockerize Graphql Rust

More current version at https://github.com/jayy-lmao/rust-cult-graphql-server

This project is currently for demonstrating the use of dataloaders in a rust-based graphql server. This demo uses:

There are definitely some improvements to be made in db requests, pagination etc. Let me know if you spot anything you think is top-priority!

Running locally

simple as docker-compose up, crazy! Then navigate to http://localhost:8000/graphql

TODO

  • DB connection
  • Expose graphql
  • Mutations!
    • Create
    • Update
    • Delete
  • Context to later use in Dataloaders and Auth
  • Dataloaders
  • Auth?
  • DB pool

Schema

type Cult {
  id: Int!
  name: String!
  members: [Person!]!
}

type Mutation {
  createPerson(data: NewPerson!): Person!
  createCult(data: NewCult!): Cult!
}

input NewCult {
  name: String!
}

input NewPerson {
  name: String!
  cult: Int
}

type Person {
  id: Int!
  name: String!
  cult: Cult
}

type Query {
  personById(id: Int!): Person!
  persons: [Person!]!
  cultById(id: Int!): Cult!
  cults: [Cult!]!
}

References

Original Rest API & DB connection is inspired by: https://turreta.com/2019/09/21/rest-api-with-rust-actix-web-and-postgresql-part-3/

Graphql setup is inspired by: https://www.freecodecamp.org/news/building-powerful-graphql-servers-with-rust/

Rust containerization initially inspired by: https://alexbrand.dev/post/how-to-package-rust-applications-into-minimal-docker-containers/

Other stuff

If you are ever looking at setting up a Redis pubsub for keeping multiple servers in sync; check out https://github.com/jayy-lmao/rust-chat-bb8-ws

If you want a more up-to-date version using actix-web and async-graphql see https://github.com/jayy-lmao/rust-cult-graphql-server

You might also like...
Rust HTTP API Template using PostgreSQL, Redis, RabbitMQ, and Hexagonal Architecture

Rust Template HTTP API Rust API Template using PostgreSQL, Redis, RabbitMQ, and Hexagonal Architecture The following template provides a basic structu

An API project using Rust, Actix Web and JWT. *WIP*

Actix-web REST API with JWT (WIP) A simple CRUD backend app using Actix-web, Diesel and JWT Require Rust Stable Postgres Or using Docker How to run Ma

Rust implementation of the `URLPattern` web API

urlpattern This crate implements the URLPattern web API in Rust. We aim to follow the specification as closely as possible. Contributing We appreciate

A pure Rust implementation of the Web Local Storage API, for use in non-browser contexts

Rust Web Local Storage API A Rust implementation of the Web LocalStorage API, for use in non-browser contexts About the Web Local Storage API MDN docs

Implementation of the RealWorld backend API spec in Actix, Rust's powerful actor system and most fun web framework.
Implementation of the RealWorld backend API spec in Actix, Rust's powerful actor system and most fun web framework.

Actix codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API. ❗ (2021/05/13) This cod

Rust Rest API Stack with User Management
Rust Rest API Stack with User Management

A secure-by-default rest api stack implemented with hyper, tokio, bb8 and postgres. This project is focused on providing end-to-end encryption by default for 12-factor applications. Includes a working user management and authentication backend written in postgresql with async S3 uploading for POST-ed data files.

Fastest autocomplete API written in rust 🦀

rust-autocomplete-api fastest* autocomplete API written in rust 🦀 *probably Run it locally cargo build --release ./target/release/autocomplete-api-po

Rust Rocket MongoDB token-authorization REST API boilerplate

Rust Rocket MongoDB token-auth REST API boilerplate In this repository, you can find backend Rust rocket mongodb rest-api boilerplate with token autho

An API to track various stats written in Rust. Tracking Github, Wakatime, Spotify, and Duolingo
An API to track various stats written in Rust. Tracking Github, Wakatime, Spotify, and Duolingo

Null API API For collecting data Explore the docs » View Demo · Report Bug · Request Feature Table of Contents About The Project Built With Getting St

Comments
  • Update dataloader and juniper dependencies

    Update dataloader and juniper dependencies

    Hi! thanks for this example.

    I updated the code for dataloader = "0.12.0" and the latest master branch of juniper

    Output from docker-compose logs
    api_1  | Connecting to postgresql://jayylmao:yeetus@db:5432
    api_1  | Connection is fine
    db_1   | 2020-05-13 18:09:09.435 UTC [98] LOG:  execute <unnamed>: SELECT id, name FROM cults
    api_1  | load persons batch [1, 2, 3]
    api_1  | Connecting to postgresql://jayylmao:yeetus@db:5432
    api_1  | Connection is fine
    db_1   | 2020-05-13 18:09:09.446 UTC [99] LOG:  execute <unnamed>: SELECT id, name, cult FROM persons WHERE cult = ANY($1)
    db_1   | 2020-05-13 18:09:09.446 UTC [99] DETAIL:  parameters: $1 = '{1,2,3}'
    api_1  | Connecting to postgresql://jayylmao:yeetus@db:5432
    api_1  | Connection is fine
    db_1   | 2020-05-13 18:09:26.563 UTC [101] LOG:  execute <unnamed>: SELECT id, name FROM cults
    api_1  | load persons batch [1, 3, 2]
    api_1  | Connecting to postgresql://jayylmao:yeetus@db:5432
    api_1  | Connection is fine
    db_1   | 2020-05-13 18:09:26.568 UTC [102] LOG:  execute <unnamed>: SELECT id, name, cult FROM persons WHERE cult = ANY($1)
    db_1   | 2020-05-13 18:09:26.568 UTC [102] DETAIL:  parameters: $1 = '{1,3,2}'
    api_1  | Connecting to postgresql://jayylmao:yeetus@db:5432
    api_1  | Connection is fine
    db_1   | 2020-05-13 18:09:31.960 UTC [103] LOG:  execute <unnamed>: SELECT id, name, cult FROM persons
    api_1  | load cult batch [1, 2]
    api_1  | Connecting to postgresql://jayylmao:yeetus@db:5432
    api_1  | Connection is fine
    db_1   | 2020-05-13 18:09:31.965 UTC [104] LOG:  execute <unnamed>: SELECT id, name FROM cults WHERE id = ANY($1)
    db_1   | 2020-05-13 18:09:31.965 UTC [104] DETAIL:  parameters: $1 = '{1,2}'
    
    opened by nemesiscodex 0
  • Missing DB column error for cults query

    Missing DB column error for cults query

    There's a missing column issue with the db. Not sure what changed, but will have to go fix it.

    api_1  | Connection is fine
    db_1   | 2021-05-15 00:34:49.446 UTC [105] ERROR:  column "cult" does not exist at character 18
    db_1   | 2021-05-15 00:34:49.446 UTC [105] STATEMENT:  SELECT id, name, cult FROM cults
    api_1  | thread 'actix-rt:worker:2' panicked at 'called `Result::unwrap()` on an `Err` value: Error(Db(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("42703"), message: "column \"cult\" does not exist", detail: None, hint: None, position: Some(Normal(18)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_relation.c"), line: Some(3359), routine: Some("errorMissingColumn") }))', src/data/cult/get_cult_all.rs:8:69
    api_1  | stack backtrace:
    api_1  |    0: rust_begin_unwind
    api_1  |              at ./rustc/2fd73fabe469357a12c2c974c140f67e7cdd76d0/library/std/src/panicking.rs:493:5
    api_1  |    1: core::panicking::panic_fmt
    api_1  |              at ./rustc/2fd73fabe469357a12c2c974c140f67e7cdd76d0/library/core/src/panicking.rs:92:14
    api_1  |    2: core::option::expect_none_failed
    api_1  |              at ./rustc/2fd73fabe469357a12c2c974c140f67e7cdd76d0/library/core/src/option.rs:1300:5
    api_1  |    3: rust_graphql::data::cult::get_cult_all::get_cult_all
    api_1  |    4: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
    api_1  |    5: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
    api_1  |    6: futures_util::stream::stream::StreamExt::poll_next_unpin
    api_1  |    7: futures_util::stream::stream::StreamExt::poll_next_unpin
    api_1  |    8: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
    api_1  |    9: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
    api_1  |   10: juniper::execute_async::{{closure}}
    api_1  |   11: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
    api_1  |   12: std::thread::local::LocalKey<T>::with
    api_1  |   13: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
    api_1  |   14: <actix_web::handler::HandlerServiceResponse<T,R> as core::future::future::Future>::poll
    api_1  |   15: <actix_web::handler::ExtractResponse<T,S> as core::future::future::Future>::poll
    api_1  |   16: <actix_web::handler::ExtractResponse<T,S> as core::future::future::Future>::poll
    api_1  |   17: <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
    api_1  |   18: <core::pin::Pin<P> as core::future::future::Future>::poll
    api_1  |   19: <futures_util::future::either::Either<A,B> as core::future::future::Future>::poll
    api_1  |   20: actix_http::h1::dispatcher::InnerDispatcher<T,S,B,X,U>::poll_response
    api_1  |   21: <actix_http::h1::dispatcher::Dispatcher<T,S,B,X,U> as core::future::future::Future>::poll
    api_1  |   22: <actix_service::and_then::AndThenServiceResponse<A,B> as core::future::future::Future>::poll
    api_1  |   23: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
    api_1  |   24: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
    api_1  |   25: tokio::task::harness::Harness<T,S>::poll
    api_1  |   26: tokio::task::local::Scheduler::tick
    api_1  |   27: std::thread::local::LocalKey<T>::with
    api_1  |   28: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
    api_1  |   29: tokio::runtime::basic_scheduler::BasicScheduler<P>::block_on
    api_1  |   30: tokio::runtime::context::enter
    api_1  | note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.```
    opened by jayy-lmao 0
Releases(0.1.0)
  • 0.1.0(Jan 30, 2020)

    :sparkles::sparkles::sparkles::sparkles::sparkles::sparkles: Currently able to work locally for querying by id's. Can currently create and read, and read actions pass through dataloaders. :sparkles::sparkles::sparkles::sparkles::sparkles::sparkles:

    🚀 Have at it! 🚀

    Source code(tar.gz)
    Source code(zip)
Owner
James H.
Masters in AI+IT && Sr. Dev @ Domain
James H.
Proof of concept writing a monolith BBS using Rust, GraphQL, WASM, and SQL. WILL BE ARCHIVED ONCE PROVEN

GraphQL Forum Important DO NOT even think about using this in production, lest your sanity be destroyed and credentials lost! Loosely following the aw

Rongcui Dong 25 Apr 25, 2023
Rust GraphQL server using simple type-only schema

SimpleGQL This library allows a simplified GraphQL schema to be given and will run a server with a backend store (currently only SQLite) and a set of

Daniel Cocks 5 May 10, 2023
Diana is a GraphQL system for Rust that's designed to work as simply as possible out of the box

Diana is a GraphQL system for Rust that's designed to work as simply as possible out of the box, without sacrificing configuration ability. Unlike other GraphQL systems, Diana fully supports serverless functions and automatically integrates them with a serverful subscriptions system as needed, and over an authenticated channel. GraphQL subscriptions are stateful, and so have to be run in a serverful way. Diana makes this process as simple as possible.

null 0 Aug 3, 2021
A Rust GraphQL system with full support for subscriptions and authentication that works out of the box.

Diana is a GraphQL system for Rust that's designed to work as simply as possible out of the box, without sacrificing configuration ability.

arctic_hen7 36 Dec 19, 2022
Rust server with Axum, GraphQL and SurrealDb

??️ Article on my web Axum server, Async-GraphQl, SurrealDB template Run without any prior setup, DB is in memory: cargo run To use routes other than

null 15 Jun 26, 2023
A fast GraphQL engine.

bluejay-rb Warning This project is still very early in its development and should be considered highly unstable and experimental. It is incomplete and

Adam Petro 4 Feb 20, 2023
mBrowser is a toy browser developed from scratch for learning purpose.

mBrowser is a toy browser developed from scratch for learning purpose.

Minh Quy 40 Oct 31, 2022
Based on the Book Computer Graphics from Scratch

raytracing_basic v1 Description Based on the Book Computer Graphics from Scratch Dependencies Good Web Game Build and run cargo build --release

null 2 Jan 28, 2022
REST API server that abstracts the need to write CRUD methods by exposing a standardized API to interact with a Postgres database

Basiliq Exposing a Postgres database via a REST API that follows the JSON:API specs. All in all, a tasty API. What is Basiliq Quickstart Ready to use

Basiliq 54 Apr 21, 2022
A secure and efficient gateway for interacting with OpenAI's API, featuring load balancing, user request handling without individual API keys, and global access control.

OpenAI Hub OpenAI Hub is a comprehensive and robust tool designed to streamline and enhance your interaction with OpenAI's API. It features an innovat

Akase Cho 30 Jun 16, 2023