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
2 changes: 0 additions & 2 deletions juniper/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,6 @@ where
QueryT: crate::GraphQLType<S, Context = CtxT>,
MutationT: crate::GraphQLType<S, Context = CtxT>,
SubscriptionT: crate::GraphQLType<S, Context = CtxT>,
SubscriptionT::TypeInfo: Send + Sync,
CtxT: Send + Sync,
{
match *self {
GraphQLBatchRequest::Single(ref request) => {
Expand Down
74 changes: 1 addition & 73 deletions juniper_rocket/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,81 +54,9 @@ use rocket::{
use juniper::{http, InputValue};

use juniper::{
serde::Deserialize, DefaultScalarValue, FieldError, GraphQLType, RootNode, ScalarValue,
http::GraphQLBatchRequest, DefaultScalarValue, FieldError, GraphQLType, RootNode, ScalarValue,
};

#[derive(Debug, serde_derive::Deserialize, PartialEq)]
#[serde(untagged)]
#[serde(bound = "InputValue<S>: Deserialize<'de>")]
enum GraphQLBatchRequest<S = DefaultScalarValue>
where
S: ScalarValue,
{
Single(http::GraphQLRequest<S>),
Batch(Vec<http::GraphQLRequest<S>>),
}

#[derive(serde_derive::Serialize)]
#[serde(untagged)]
enum GraphQLBatchResponse<'a, S = DefaultScalarValue>
where
S: ScalarValue,
{
Single(http::GraphQLResponse<'a, S>),
Batch(Vec<http::GraphQLResponse<'a, S>>),
}

impl<S> GraphQLBatchRequest<S>
where
S: ScalarValue,
{
pub fn execute_sync<'a, CtxT, QueryT, MutationT, SubscriptionT>(
&'a self,
root_node: &'a RootNode<QueryT, MutationT, SubscriptionT, S>,
context: &CtxT,
) -> GraphQLBatchResponse<'a, S>
where
QueryT: GraphQLType<S, Context = CtxT>,
MutationT: GraphQLType<S, Context = CtxT>,
SubscriptionT: GraphQLType<S, Context = CtxT>,
{
match *self {
GraphQLBatchRequest::Single(ref request) => {
GraphQLBatchResponse::Single(request.execute_sync(root_node, context))
}
GraphQLBatchRequest::Batch(ref requests) => GraphQLBatchResponse::Batch(
requests
.iter()
.map(|request| request.execute_sync(root_node, context))
.collect(),
),
}
}

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()
}
}
}
}

impl<'a, S> GraphQLBatchResponse<'a, S>
where
S: ScalarValue,
{
fn is_ok(&self) -> bool {
match *self {
GraphQLBatchResponse::Single(ref response) => response.is_ok(),
GraphQLBatchResponse::Batch(ref responses) => {
responses.iter().all(|response| response.is_ok())
}
}
}
}

/// Simple wrapper around an incoming GraphQL request
///
/// See the `http` module for more information. This type can be constructed
Expand Down
10 changes: 4 additions & 6 deletions juniper_rocket_async/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use juniper::{
#[derive(Debug, PartialEq)]
pub struct GraphQLRequest<S = DefaultScalarValue>(GraphQLBatchRequest<S>)
where
S: ScalarValue + Send + Sync;
S: ScalarValue;

/// Simple wrapper around the result of executing a GraphQL query
pub struct GraphQLResponse(pub Status, pub String);
Expand All @@ -85,9 +85,9 @@ pub fn playground_source(graphql_endpoint_url: &str) -> content::Html<String> {

impl<S> GraphQLRequest<S>
where
S: ScalarValue + Sync + Send,
S: ScalarValue,
{
/// Execute an incoming GraphQL query synchronously.
/// Synchronously execute an incoming GraphQL query.
pub fn execute_sync<CtxT, QueryT, MutationT, SubscriptionT>(
&self,
root_node: &RootNode<QueryT, MutationT, SubscriptionT, S>,
Expand All @@ -97,8 +97,6 @@ where
QueryT: GraphQLType<S, Context = CtxT>,
MutationT: GraphQLType<S, Context = CtxT>,
SubscriptionT: GraphQLType<S, Context = CtxT>,
SubscriptionT::TypeInfo: Send + Sync,
CtxT: Send + Sync,
{
let response = self.0.execute_sync(root_node, context);
let status = if response.is_ok() {
Expand All @@ -111,7 +109,7 @@ where
GraphQLResponse(status, json)
}

/// Asynchronously execute an incoming GraphQL query
/// Asynchronously execute an incoming GraphQL query.
pub async fn execute<CtxT, QueryT, MutationT, SubscriptionT>(
&self,
root_node: &RootNode<'_, QueryT, MutationT, SubscriptionT, S>,
Expand Down