Skip to content

Commit

Permalink
Update Rocket Starwars and add Rocket Upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Weasy666 committed May 20, 2021
1 parent b5c8853 commit 64e75d3
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ members = [
"tide/subscription",

"rocket/starwars",
"rocket/upload",
]
6 changes: 3 additions & 3 deletions rocket/starwars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Daniel Wiesenberg <daniel@simplificAR.io>"]
edition = "2018"

[dependencies]
async-graphql = { path = "../../..", version = "2.0.3" }
async-graphql-rocket = { path = "../../../integrations/rocket", version = "2.0.3" }
rocket = { git = "https://github.com/SergioBenitez/Rocket/", rev = "2893ce7", default-features = false } # TODO: Change to Cargo crate when Rocket 0.5.0 is released
async-graphql = { path = "../../.." }
async-graphql-rocket = { path = "../../../integrations/rocket" }
rocket = { git = "https://github.com/SergioBenitez/Rocket/", rev = "fa3e033", default-features = false } # TODO: Change to Cargo crate when Rocket 0.5.0 is released
starwars = { path = "../../models/starwars" }
12 changes: 6 additions & 6 deletions rocket/starwars/Rocket.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
[global.limits]
graphql = 131072

[development]
address = "localhost"
[debug]
address = "127.0.0.1"
port = 8000
keep_alive = 5
log = "normal"
log_level = "normal"


[staging]
address = "0.0.0.0"
port = 8080
keep_alive = 5
log = "normal"
log_level = "normal"


[production]
[release]
address = "0.0.0.0"
port = 8080
keep_alive = 5
log = "critical"
log_level = "critical"
12 changes: 6 additions & 6 deletions rocket/starwars/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ fn graphql_playground() -> content::Html<String> {
}

#[rocket::get("/graphql?<query..>")]
async fn graphql_query(schema: State<'_, StarWarsSchema>, query: Query) -> Response {
query.execute(&schema).await
async fn graphql_query(schema: &State<StarWarsSchema>, query: Query) -> Response {
query.execute(schema).await
}

#[rocket::post("/graphql", data = "<request>", format = "application/json")]
async fn graphql_request(schema: State<'_, StarWarsSchema>, request: Request) -> Response {
request.execute(&schema).await
async fn graphql_request(schema: &State<StarWarsSchema>, request: Request) -> Response {
request.execute(schema).await
}

#[rocket::launch]
fn rocket() -> rocket::Rocket {
fn rocket() -> _ {
let schema = Schema::build(QueryRoot, EmptyMutation, EmptySubscription)
.data(StarWars::new())
.finish();

rocket::ignite().manage(schema).mount(
rocket::build().manage(schema).mount(
"/",
routes![graphql_query, graphql_request, graphql_playground],
)
Expand Down
11 changes: 11 additions & 0 deletions rocket/upload/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "rocket-upload"
version = "0.1.1"
authors = ["Daniel Wiesenberg <daniel@simplificAR.io>"]
edition = "2018"

[dependencies]
async-graphql = { path = "../../.." }
async-graphql-rocket = { path = "../../../integrations/rocket" }
rocket = { git = "https://github.com/SergioBenitez/Rocket/", rev = "fa3e033", default-features = false } # TODO: Change to Cargo crate when Rocket 0.5.0 is released
files = { path = "../../models/files" }
23 changes: 23 additions & 0 deletions rocket/upload/Rocket.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# For more information take a look at https://rocket.rs/guide/configuration/
[global.limits]
graphql = 131072

[debug]
address = "127.0.0.1"
port = 8000
keep_alive = 5
log_level = "normal"


[staging]
address = "0.0.0.0"
port = 8080
keep_alive = 5
log_level = "normal"


[release]
address = "0.0.0.0"
port = 8080
keep_alive = 5
log_level = "critical"
41 changes: 41 additions & 0 deletions rocket/upload/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig},
EmptyMutation, EmptySubscription, Schema,
};
use async_graphql_rocket::{Query, Request, Response};
use rocket::{response::content, routes, State};
use files::{FilesSchema, MutationRoot, QueryRoot, Storage};

pub type StarWarsSchema = Schema<QueryRoot, EmptyMutation, EmptySubscription>;

#[rocket::get("/")]
fn graphql_playground() -> content::Html<String> {
content::Html(playground_source(GraphQLPlaygroundConfig::new("/graphql")))
}

#[rocket::get("/graphql?<query..>")]
async fn graphql_query(schema: &State<FilesSchema>, query: Query) -> Response {
query.execute(schema).await
}

#[rocket::post("/graphql", data = "<request>", format = "application/json", rank = 1)]
async fn graphql_request(schema: &State<FilesSchema>, request: Request) -> Response {
request.execute(schema).await
}

#[rocket::post("/graphql", data = "<request>", format = "multipart/form-data", rank = 2)]
async fn graphql_request_multipart(schema: &State<FilesSchema>, request: Request) -> Response {
request.execute(schema).await
}

#[rocket::launch]
fn rocket() -> _ {
let schema = Schema::build(QueryRoot, MutationRoot, EmptySubscription)
.data(Storage::default())
.finish();

rocket::build().manage(schema).mount(
"/",
routes![graphql_query, graphql_request, graphql_request_multipart, graphql_playground],
)
}

0 comments on commit 64e75d3

Please sign in to comment.