diff --git a/juniper_iron/src/lib.rs b/juniper_iron/src/lib.rs index 3d0eff38..8f0ab075 100644 --- a/juniper_iron/src/lib.rs +++ b/juniper_iron/src/lib.rs @@ -122,72 +122,10 @@ use std::{error::Error, fmt, io::Read}; use serde_json::error::Error as SerdeError; use juniper::{ - http, serde::Deserialize, DefaultScalarValue, GraphQLType, InputValue, RootNode, ScalarValue, + http, http::GraphQLBatchRequest, DefaultScalarValue, GraphQLType, InputValue, RootNode, + ScalarValue, }; -#[derive(serde_derive::Deserialize)] -#[serde(untagged)] -#[serde(bound = "InputValue: Deserialize<'de>")] -enum GraphQLBatchRequest -where - S: ScalarValue, -{ - Single(http::GraphQLRequest), - Batch(Vec>), -} - -#[derive(serde_derive::Serialize)] -#[serde(untagged)] -enum GraphQLBatchResponse<'a, S = DefaultScalarValue> -where - S: ScalarValue, -{ - Single(http::GraphQLResponse<'a, S>), - Batch(Vec>), -} - -impl GraphQLBatchRequest -where - S: ScalarValue, -{ - pub fn execute_sync<'a, CtxT, QueryT, MutationT, Subscription>( - &'a self, - root_node: &'a RootNode, - context: &CtxT, - ) -> GraphQLBatchResponse<'a, S> - where - QueryT: GraphQLType, - MutationT: GraphQLType, - Subscription: GraphQLType, - { - 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(), - ), - } - } -} - -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()) - } - } - } -} - /// Handler that executes `GraphQL` queries in the given schema /// /// The handler responds to GET requests and POST requests only. In GET