Code Monkey home page Code Monkey logo

zzy / actix-web-async-graphql-rbatis Goto Github PK

View Code? Open in Web Editor NEW
28.0 1.0 5.0 114 KB

Clean boilerplate for graphql services using actix-web, rhai, async-graphql, surf, rbatis, graphql-client, handlebars-rust, jsonwebtoken, and mysql / postgresql.

Home Page: https://blog.budshome.com/topics/graphql

License: Apache License 2.0

Rust 100.00%
rust actix-web async-graphql postgresql mysql graphql-server graphql-client surf jwt-authentication jsonwebtoken

actix-web-async-graphql-rbatis's Introduction

actix-web-async-graphql-rbatis

Clean boilerplate for graphql services using actix-web, rhai, async-graphql, surf, rbatis, graphql-client, handlebars-rust, jsonwebtoken, and mysql / postgresql.

See also: tide-async-graphql-mongodb

Features

  • Graphql Services
    • User register
    • Salt and hash a password with PBKDF2 - 使用 PBKDF2 对密码进行加密(salt)和散列(hash)运算
    • Sign in
    • JSON web token authentication - JWT 鉴权整合
    • Change password
    • Profile Update
    • User: query & mutation
    • Project: query & mutation
  • Web Application
    • Client request, bring & parse GraphQL data
    • Render data to template engine
    • Define custom helper with Rhai scripting language

Stacks

How to run?

git clone https://github.com/zzy/actix-web-async-graphql.git
cd actix-web-async-graphql
cargo build

Frontend - actix-web server

cd frontend-handlebars

Rename file .env.example to .env, or put the environment variables into a .env file:

ADDRESS=127.0.0.1
PORT=3000

GRAPHQL_PORT=8080
GRAPHQL_PATH=graphql
GRAPHIQL_PATH=graphiql

Build & Run:

cargo run

Then connect to http://127.0.0.1:3000 with browser.

Client Image

Backend - Graphql Server

cd backend

Rename file .env.example to .env, or put the environment variables into a .env file:

ADDRESS=127.0.0.1
PORT=8080

GRAPHQL_PATH=graphql
GRAPHIQL_PATH=graphiql

MYSQL_URI=mysql://root:mysql@localhost:3306/budshome
POSTGRES_URI=postgres://root:mysql@localhost:5432/budshome

SITE_KEY=0F4EHz+1/hqVvZjuB8EcooQs1K6QKBvLUxqTHt4tpxE=
CLAIM_EXP=10000000000

Build & Run:

cargo run

GraphiQL: connect to http://127.0.0.1:8080/graphiql with browser.

Graphql Image

Queries

  • getUserByEmail(...): User!
  • getUserByUsername(...): User!
  • userSignIn(...): SignInfo!
  • allUsers(...): [User!]!
  • allProjects: [Project!]!
  • allProjectsByUser(...): [Project!]!

MUTATIONS

  • userRegister(...): User!
  • userChangePassword(...): User!
  • userUpdateProfile(...): User!
  • addProject(...): Project!

Sample Usage

Sample mutation for user register:

mutation {
  userRegister(
    newUser: { 
      email: "[email protected]", 
      username: "我是谁", 
      password: "wo#$shi^$shui" 
    }
  ) {
    id
    email
    username
  }
}

Sample query for user sign in:

{
  userSignIn(
    userAccount: {
      email: "[email protected]"
      username: ""
      password: "wo#$shi^$shui"
    }
  ) {
    email
    username
    token
  }
}

When submit method userSignIn, a token would be generated, use this token for query all users and every user's projects:

{
  allUsers(
    token: "fyJ0eXAiOiJKV1Q..."
  ) {
    id
    email
    username

    projects {
      id
      userId
      subject
      website
    }
  }
}

Sample query and mutation for projects was similar to users.

Contributing

You are welcome in contributing to this project.

actix-web-async-graphql-rbatis's People

Contributors

dependabot[bot] avatar zzy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.