A Boilerplate of GraphQL API built in Rust + Warp + Juniper + Diesel
MIT License
This is a boilerplate built with Rust.
$ 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
$ 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
to0.0.0.0
inmain.rs
. Because rust GraphQL API in docker container needs to listen to0.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
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.
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
}
}
}