Skip to content

Commit 2618100

Browse files
authored
Update juniper_rocket to central GraphQLBatch* enums (#614)
1 parent 6b040c5 commit 2618100

File tree

3 files changed

+5
-81
lines changed

3 files changed

+5
-81
lines changed

juniper/src/http/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,6 @@ where
247247
QueryT: crate::GraphQLType<S, Context = CtxT>,
248248
MutationT: crate::GraphQLType<S, Context = CtxT>,
249249
SubscriptionT: crate::GraphQLType<S, Context = CtxT>,
250-
SubscriptionT::TypeInfo: Send + Sync,
251-
CtxT: Send + Sync,
252250
{
253251
match *self {
254252
GraphQLBatchRequest::Single(ref request) => {

juniper_rocket/src/lib.rs

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -54,81 +54,9 @@ use rocket::{
5454
use juniper::{http, InputValue};
5555

5656
use juniper::{
57-
serde::Deserialize, DefaultScalarValue, FieldError, GraphQLType, RootNode, ScalarValue,
57+
http::GraphQLBatchRequest, DefaultScalarValue, FieldError, GraphQLType, RootNode, ScalarValue,
5858
};
5959

60-
#[derive(Debug, serde_derive::Deserialize, PartialEq)]
61-
#[serde(untagged)]
62-
#[serde(bound = "InputValue<S>: Deserialize<'de>")]
63-
enum GraphQLBatchRequest<S = DefaultScalarValue>
64-
where
65-
S: ScalarValue,
66-
{
67-
Single(http::GraphQLRequest<S>),
68-
Batch(Vec<http::GraphQLRequest<S>>),
69-
}
70-
71-
#[derive(serde_derive::Serialize)]
72-
#[serde(untagged)]
73-
enum GraphQLBatchResponse<'a, S = DefaultScalarValue>
74-
where
75-
S: ScalarValue,
76-
{
77-
Single(http::GraphQLResponse<'a, S>),
78-
Batch(Vec<http::GraphQLResponse<'a, S>>),
79-
}
80-
81-
impl<S> GraphQLBatchRequest<S>
82-
where
83-
S: ScalarValue,
84-
{
85-
pub fn execute_sync<'a, CtxT, QueryT, MutationT, SubscriptionT>(
86-
&'a self,
87-
root_node: &'a RootNode<QueryT, MutationT, SubscriptionT, S>,
88-
context: &CtxT,
89-
) -> GraphQLBatchResponse<'a, S>
90-
where
91-
QueryT: GraphQLType<S, Context = CtxT>,
92-
MutationT: GraphQLType<S, Context = CtxT>,
93-
SubscriptionT: GraphQLType<S, Context = CtxT>,
94-
{
95-
match *self {
96-
GraphQLBatchRequest::Single(ref request) => {
97-
GraphQLBatchResponse::Single(request.execute_sync(root_node, context))
98-
}
99-
GraphQLBatchRequest::Batch(ref requests) => GraphQLBatchResponse::Batch(
100-
requests
101-
.iter()
102-
.map(|request| request.execute_sync(root_node, context))
103-
.collect(),
104-
),
105-
}
106-
}
107-
108-
pub fn operation_names(&self) -> Vec<Option<&str>> {
109-
match self {
110-
GraphQLBatchRequest::Single(req) => vec![req.operation_name()],
111-
GraphQLBatchRequest::Batch(reqs) => {
112-
reqs.iter().map(|req| req.operation_name()).collect()
113-
}
114-
}
115-
}
116-
}
117-
118-
impl<'a, S> GraphQLBatchResponse<'a, S>
119-
where
120-
S: ScalarValue,
121-
{
122-
fn is_ok(&self) -> bool {
123-
match *self {
124-
GraphQLBatchResponse::Single(ref response) => response.is_ok(),
125-
GraphQLBatchResponse::Batch(ref responses) => {
126-
responses.iter().all(|response| response.is_ok())
127-
}
128-
}
129-
}
130-
}
131-
13260
/// Simple wrapper around an incoming GraphQL request
13361
///
13462
/// See the `http` module for more information. This type can be constructed

juniper_rocket_async/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ use juniper::{
6565
#[derive(Debug, PartialEq)]
6666
pub struct GraphQLRequest<S = DefaultScalarValue>(GraphQLBatchRequest<S>)
6767
where
68-
S: ScalarValue + Send + Sync;
68+
S: ScalarValue;
6969

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

8686
impl<S> GraphQLRequest<S>
8787
where
88-
S: ScalarValue + Sync + Send,
88+
S: ScalarValue,
8989
{
90-
/// Execute an incoming GraphQL query synchronously.
90+
/// Synchronously execute an incoming GraphQL query.
9191
pub fn execute_sync<CtxT, QueryT, MutationT, SubscriptionT>(
9292
&self,
9393
root_node: &RootNode<QueryT, MutationT, SubscriptionT, S>,
@@ -97,8 +97,6 @@ where
9797
QueryT: GraphQLType<S, Context = CtxT>,
9898
MutationT: GraphQLType<S, Context = CtxT>,
9999
SubscriptionT: GraphQLType<S, Context = CtxT>,
100-
SubscriptionT::TypeInfo: Send + Sync,
101-
CtxT: Send + Sync,
102100
{
103101
let response = self.0.execute_sync(root_node, context);
104102
let status = if response.is_ok() {
@@ -111,7 +109,7 @@ where
111109
GraphQLResponse(status, json)
112110
}
113111

114-
/// Asynchronously execute an incoming GraphQL query
112+
/// Asynchronously execute an incoming GraphQL query.
115113
pub async fn execute<CtxT, QueryT, MutationT, SubscriptionT>(
116114
&self,
117115
root_node: &RootNode<'_, QueryT, MutationT, SubscriptionT, S>,

0 commit comments

Comments
 (0)