-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Rocket Starwars and add Rocket Upload
- Loading branch information
Showing
7 changed files
with
91 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,5 @@ members = [ | |
"tide/subscription", | ||
|
||
"rocket/starwars", | ||
"rocket/upload", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
) | ||
} |