Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ members = [
"juniper_hyper",
"juniper_iron",
"juniper_rocket",
"juniper_rocket_async",
"juniper_subscriptions",
"juniper_warp",
]
exclude = [
"docs/book/tests",
"examples/warp_async",
"examples/warp_subscriptions",
# TODO enable async tests
"juniper_rocket_async",
]
3 changes: 3 additions & 0 deletions juniper/release.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pre-release-replacements = [
# Rocket
{file="../juniper_rocket/Cargo.toml", search="juniper = \\{ version = \"[^\"]+\"", replace="juniper = { version = \"{{version}}\""},
{file="../juniper_rocket/Cargo.toml", search="\\[dev-dependencies\\.juniper\\]\nversion = \"[^\"]+\"", replace="[dev-dependencies.juniper]\nversion = \"{{version}}\""},
# Rocket Async
{file="../juniper_rocket_async/Cargo.toml", search="juniper = \\{ version = \"[^\"]+\"", replace="juniper = { version = \"{{version}}\""},
{file="../juniper_rocket_async/Cargo.toml", search="\\[dev-dependencies\\.juniper\\]\nversion = \"[^\"]+\"", replace="[dev-dependencies.juniper]\nversion = \"{{version}}\""},
# Warp
{file="../juniper_warp/Cargo.toml", search="juniper = \\{ version = \"[^\"]+\"", replace="juniper = { version = \"{{version}}\""},
{file="../juniper_warp/Cargo.toml", search="\\[dev-dependencies\\.juniper\\]\nversion = \"[^\"]+\"", replace="[dev-dependencies.juniper]\nversion = \"{{version}}\""},
Expand Down
10 changes: 10 additions & 0 deletions juniper/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@ where
}
}
}

/// The operation names of the request.
pub fn operation_names(&self) -> Vec<Option<&str>> {
match self {
GraphQLBatchRequest::Single(req) => vec![req.operation_name()],
GraphQLBatchRequest::Batch(reqs) => {
reqs.iter().map(|req| req.operation_name()).collect()
}
}
}
}

/// Simple wrapper around the result (GraphQLResponse) from executing a GraphQLBatchRequest
Expand Down
7 changes: 3 additions & 4 deletions juniper_rocket_async/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "juniper_rocket"
name = "juniper_rocket_async"
version = "0.5.1"
authors = [
"Magnus Hallin <mhallin@fastmail.com>",
Expand All @@ -15,11 +15,10 @@ edition = "2018"
serde = { version = "1.0.2" }
serde_json = { version = "1.0.2" }
serde_derive = { version = "1.0.2" }
juniper = { version = "0.14.1", default-features = false, path = "../juniper"}

juniper = { version = "0.14.2", default-features = false, path = "../juniper" }
futures = { version = "0.3.1", features = ["compat"] }
rocket = { git = "https://github.com/SergioBenitez/Rocket", branch = "async", default-features = false }
tokio = "0.2"
tokio = { version = "0.2", features = ["rt-core", "macros"] }

[dev-dependencies.juniper]
version = "0.14.1"
Expand Down
23 changes: 14 additions & 9 deletions juniper_rocket_async/examples/rocket_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,46 @@ use rocket::{response::content, State};

use juniper::{
tests::{model::Database, schema::Query},
EmptyMutation, RootNode,
EmptyMutation, EmptySubscription, RootNode,
};

type Schema = RootNode<'static, Query, EmptyMutation<Database>>;
type Schema = RootNode<'static, Query, EmptyMutation<Database>, EmptySubscription<Database>>;

#[rocket::get("/")]
fn graphiql() -> content::Html<String> {
juniper_rocket::graphiql_source("/graphql")
juniper_rocket_async::graphiql_source("/graphql")
}

#[rocket::get("/graphql?<request>")]
fn get_graphql_handler(
context: State<Database>,
request: juniper_rocket::GraphQLRequest,
request: juniper_rocket_async::GraphQLRequest,
schema: State<Schema>,
) -> juniper_rocket::GraphQLResponse {
) -> juniper_rocket_async::GraphQLResponse {
request.execute_sync(&schema, &context)
}

#[rocket::post("/graphql", data = "<request>")]
fn post_graphql_handler(
context: State<Database>,
request: juniper_rocket::GraphQLRequest,
request: juniper_rocket_async::GraphQLRequest,
schema: State<Schema>,
) -> juniper_rocket::GraphQLResponse {
) -> juniper_rocket_async::GraphQLResponse {
request.execute_sync(&schema, &context)
}

fn main() {
rocket::ignite()
.manage(Database::new())
.manage(Schema::new(Query, EmptyMutation::<Database>::new()))
.manage(Schema::new(
Query,
EmptyMutation::<Database>::new(),
EmptySubscription::<Database>::new(),
))
.mount(
"/",
rocket::routes![graphiql, get_graphql_handler, post_graphql_handler],
)
.launch();
.launch()
.expect("server to launch");
}
Loading