Coder Social home page Coder Social logo

kusanagi2501 / rust_graphql_api_boilerplate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mununki/rust_graphql_api_boilerplate

0.0 1.0 0.0 30 KB

A Boilerplate of GraphQL API built in Rust + Warp + Juniper + Diesel

PLpgSQL 8.90% Rust 86.10% Dockerfile 2.45% TSQL 2.55%

rust_graphql_api_boilerplate's Introduction

Rust GraphQL API Boilerplate

This is a boilerplate built with Rust.

Features

  • DB migration with Diesel
  • Sign up
  • Sign in
  • Change password
  • Profile Update
  • JSON web token authentication

Stacks

  • Rust
  • Warp - Web server framework
  • Juniper - GraphQL library
  • Diesel - ORM
  • DB: Postgres
  • JSON Web Token : Authentication

Run

Without Docker

$ git clone https://github.com/mattdamon108/rust_graphql_api_boilerplate
$ cd rust_graphql_api_boilerplate
$ echo DATABASE_URL=postgres://username:password@localhost/rust_boilerplate > .env
$ diesel setup
$ diesel migration run
$ cargo run

Build with Docker

$ docker build -t rust_gql .
$ docker run --rm -d -p 3030:3030 --name running_rust_gql rust_gql

Change the listening port from 127.0.0.1 to 0.0.0.0 in main.rs. Because rust GraphQL API in docker container needs to listen to 0.0.0.0 instead of local interface in order for host to access to the API.

GraphiQL : connect to 127.0.0.1:3030 with browser

Schema

Query

query {
  getMyProfile {
    ok
    error
    user {
      id
      email
      first_name
      last_name
      bio
      avatar
    }
  }
}

Note: JSON web token is needed to be sent as authorization in header.

Mutation

Sign Up

mutation {
  signUp(
    email: "[email protected]"
    password: "12345678"
    firstName: "graphql"
    lastName: "rust"
  ) {
    ok
    error
    user {
      id
      email
      first_name
      last_name
      bio
      avatar
    }
  }
}

Sign In

mutation {
  signIn(email: "[email protected]", password: "12345678") {
    token
  }
}

Change Password

Note: JSON web token is needed to be sent as authorization in header.

mutation {
  changePassword(password: "87654321") {
    ok
    error
    user {
      id
      email
      first_name
      last_name
      bio
      avatar
    }
  }
}

Change Profile

Note: JSON web token is needed to be sent as authorization in header.

mutation {
  changeProfile(bio: "Rust fan") {
    ok
    error
    user {
      id
      email
      first_name
      last_name
      bio
      avatar
    }
  }
}

Next to do

  • User Sign up
  • Hash User Password - with bcrypt crate
  • User Sign in based on Token authentication
  • User profile Update
  • ERROR HANDLING (important!)
  • Deploy using Docker after compile
  • Optimizing the multithread

References

rust_graphql_api_boilerplate's People

Contributors

mununki avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.