canduma / canduma Goto Github PK
View Code? Open in Web Editor NEWA Rust Boilerplate server with GraphQL API, Diesel, PostgreSQL, session authentication and JWT
License: MIT License
A Rust Boilerplate server with GraphQL API, Diesel, PostgreSQL, session authentication and JWT
License: MIT License
The project could get a boost in performance by utilizing connection pools with r2d2 and Postgres. This is already flagged as a feature within the cargo.toml for diesel.
This is something most likely I could support with a PR, but wanted to have a discussion for desire before implementing.
Hi.
Would you like to support cursor-based pagination. So the query will contains nodes
, edges
, pageInfo
, and totalCount
.
Such:
{
hero {
name
friends(first:2) {
totalCount
edges {
node {
name
}
cursor
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
Or something like:
Contexts:
@clifinger did you know about async-graphql
At this moment this solution has more features and I feel better then use of jupiter.
I personally followed the implementation of twentyfive-stars and liked the interface more than Jupiter. Jupiter supports async, but not released yet and Jupiter lack of good documentation when async-graphql has excellent book
During the investigation, I came across sqlx and found this native rust driver feature to verify SQL during the build is awesome and helps to find bugs before the actual run.
There are actually 3 choices:
I have tried all 3 and finally stopped on sqlx, diesel is crazy complex and not native driver, tokio-postgres is too basic and sqlx is a very good balanced generic solution and I feel performance would be better as it does not have a dependency on libpq (C driver)
I think, that for Bollerplate we need to pick the best solutions on the market and diesel and Jupiter are not the best
In Node.js GraphQL servers you simply give as context functions that handle the cookies/session to do the authentication, but in this template the authentication is being handled outside of GraphQL, how can I handle it all inside GraphQL? when I try to simply give the actix session stuff it just says it can't be shared between threads.
I like this project as it's a really easy to use boilerplate for Rust projects. I use Heroku sometimes and also Dokku/Docker so it would be nice to easily use canduma with Heroku instead of building it myself.
Edit: So I was able to use the buildpack at https://github.com/emk/heroku-buildpack-rust to build canduma on Dokku on a DigitalOcean droplet. Since it uses Heroku buildpacks, this should be compatible with Heroku as well. Looks like there may be some bugs with the buildpack on Heroku's buildpack library, so use the full https://github.com/emk/heroku-buildpack-rust url instead when adding the buildpack.
Heroku: heroku buildpacks:set https://github.com/emk/heroku-buildpack-rust.git
Dokku: dokku buildpacks:add https://github.com/emk/heroku-buildpack-rust.git
If you don't set the buildpack as being Rust based, Heroku/Dokku assume it's a NodeJS app due to the package.json
in the directory, and the build will fail. Actually, why is there a package.json
in the project anyway? Looks like it's used for linting and testing, but I'm not sure what parts are JS based exactly.
Since async/await has landed with Rust 1.39.0, it would be worthwhile to take advantage of the new syntax.
Get JWT Token (http://localhost:3000/graphql), server returns
{
"data": null,
"errors": [
{
"message": "Unauthorized",
"locations": [
{
"line": 14,
"column": 3
}
],
"path": [
"decodeToken"
],
"extensions": {
"type": "NO_ACCESS"
}
}
]
}
Something may be needed when sending Get JWT Token request.
Currently response are not all json. For example if we register using same information twice following is the raw data instead of helpful json message like Wrong username or password.
BadRequest: Key (email)=([email protected]) already exists.
What do you think about using oxide-auth ?
$ cargo run --example actix
I would like to promote my crate wundergraph. It greatly simplifies the creation of a performant GraphQL over given relational database schema.
Implementations using diesel and juniper in a straight forward most likely have problems with N+1 queries while resolving a nested GraphQL entity. Wundergraph is build on top of diesel and juniper and circumvents this problems carefully craft a fixed number(= independent of the actual number of loaded database entries) of SQL queries to resolve one GraphQL request.
(This seems to be not the case for this example, because there is only one GraphQL entity that is mapped to a database entity, but if this should be a good starting point for a real world application it's probably worth to change it anyway.)
Add federation support to GraphQL for micro-services (and use the JWT as claims to exchange data between services).
$ cargo run
info: syncing channel updates for '1.40.0-x86_64-apple-darwin'
info: latest update on 2019-12-19, rust version 1.40.0 (73528e339 2019-12-16)
Compiling ...
Compiling tokio-fs v0.1.6
error: no rules expected the token `#`
--> /Users/swordsman/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/err-derive-0.2.2/src/lib.rs:138:59
|
138 | decl_derive!([Error, attributes(error, source, cause)] => #[proc_macro_error] error_derive);
| ^ no rules expected this token in macro call
os: macos Catalina 10.15.2
rust: rustc 1.40.0 (73528e339 2019-12-16)
Currently implementing it on actix-web repo.
Actix RedisSessionBackend to include same features as CookiSessionBackend from actix-web like max-age.
Diesel updated with version 2.0
Updated Cargo.toml
diesel = { version = "2.0.0", features = ["postgres", "uuid", "chrono", "r2d2"] }
See these errors:
warning: #[table_name] attribute form is deprecated
= help: use `#[diesel(table_name = users)]` instead
error[E0308]: mismatched types
--> src/user/service/list.rs:18:23
|
18 | .load::<User>(conn)?)
| ------------ ^^^^ types differ in mutability
| |
| arguments to this function are incorrect
|
= note: expected mutable reference `&mut _`
found reference `&diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>`
note: associated function defined here
--> /home//.cargo/registry/src/github.com-1ecc6299db9ec823/diesel-2.0.0/src/query_dsl/mod.rs:1497:8
|
1497 | fn load<'query, U>(self, conn: &mut Conn) -> QueryResult<Vec<U>>
| ^^^^
error[E0308]: mismatched types
--> src/user/service/login.rs:18:24
|
18 | .first::<User>(conn)
| ------------- ^^^^ types differ in mutability
| |
| arguments to this function are incorrect
|
= note: expected mutable reference `&mut _`
found reference `&diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>`
note: associated function defined here
--> /home//.cargo/registry/src/github.com-1ecc6299db9ec823/diesel-2.0.0/src/query_dsl/mod.rs:1733:8
|
1733 | fn first<'query, U>(self, conn: &mut Conn) -> QueryResult<U>
| ^^^^^
error[E0308]: mismatched types
--> src/user/service/register.rs:16:83
|
16 | let inserted_user: User = diesel::insert_into(users).values(&user).get_result(conn)?;
| ---------- ^^^^ types differ in mutability
| |
| arguments to this function are incorrect
|
= note: expected mutable reference `&mut _`
found reference `&diesel::PgConnection`
note: associated function defined here
--> /home//.cargo/registry/src/github.com-1ecc6299db9ec823/diesel-2.0.0/src/query_dsl/mod.rs:1677:8
|
1677 | fn get_result<'query, U>(self, conn: &mut Conn) -> QueryResult<U>
| ^^^^^^^^^^
For more information about this error, try `rustc --explain E0308`.
error: could not compile `canduma` due to 3 previous errors
I've registered and logged in and have the cookie with auth
set, but running this query:
https://github.com/clifinger/canduma/blob/master/docs/images/new-insomnia-grahql-get-jwt.png
I'm getting this result:
{
"errors": [
{
"message": "Unknown field \"token\" on type \"QueryRoot\"",
"locations": [
{
"line": 11,
"column": 5
}
]
},
{
"message": "Unknown field \"decode\" on type \"QueryRoot\"",
"locations": [
{
"line": 17,
"column": 5
}
]
}
]
}
Was the schema changed since the getting started steps were made?
How would you suggest adding a new table (struct) to the app? for instance if I wanted each user to have "messages" how would I add that (to be inline with the overall app and API)
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.