Skip to content

Commit 7d7e7e6

Browse files
committed
Don't depend on serde_json by default, rename some structs
1 parent 7041efe commit 7d7e7e6

File tree

4 files changed

+21
-28
lines changed

4 files changed

+21
-28
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ name = "server"
2020
required-features = ["iron-handlers", "expose-test-schema"]
2121

2222
[features]
23-
default = ["serde", "serde_json"]
2423
nightly = []
25-
iron-handlers = ["iron", "default", "serde_derive", "urlencoded"]
24+
iron-handlers = ["iron", "serde_json", "urlencoded"]
2625
expose-test-schema = []
2726

2827
[dependencies]
28+
serde = { version = "^0.9.1" }
29+
serde_derive = {version="^0.9.1" }
30+
2931
iron = { version = "^0.5.1", optional = true }
30-
serde = { version = "^0.9.1", optional = true }
3132
serde_json = {version ="^0.9.1", optional = true }
32-
serde_derive = {version="^0.9.1", optional = true }
3333
urlencoded = {version="0.5", optional=true}
3434

3535

src/integrations/iron_handlers.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use serde_json;
1717
use serde_json::error::Error as SerdeError;
1818

1919
use ::{InputValue, GraphQLType, RootNode, execute};
20-
use super::serde::{WrappedGraphQLResult, GraphQlQuery};
20+
use super::serde::{WrappedGraphQLResult, GraphQLQuery};
2121

2222
/// Handler that executes GraphQL queries in the given schema
2323
///
@@ -112,7 +112,7 @@ impl<'a, CtxFactory, Query, Mutation, CtxT>
112112
}
113113

114114

115-
fn handle_get(&self, req: &mut Request) -> IronResult<GraphQlQuery> {
115+
fn handle_get(&self, req: &mut Request) -> IronResult<GraphQLQuery> {
116116
match req.get_mut::<UrlEncodedQuery>() {
117117
Ok(ref mut query_string) => {
118118
let input_query = parse_url_param(query_string.remove("query").to_owned())?;
@@ -121,7 +121,7 @@ impl<'a, CtxFactory, Query, Mutation, CtxT>
121121
parse_url_param(query_string.remove("operationName"))?;
122122
let input_variables =
123123
parse_variable_param(query_string.remove("variables"))?;
124-
Ok(GraphQlQuery::new(query,operation_name,input_variables))
124+
Ok(GraphQLQuery::new(query,operation_name,input_variables))
125125
} else {
126126
Err(IronError::new(
127127
Box::new(GraphQlIronError::IO(IoError::new(ErrorKind::InvalidData,
@@ -138,18 +138,18 @@ impl<'a, CtxFactory, Query, Mutation, CtxT>
138138
}
139139
}
140140

141-
fn handle_post(&self, req: &mut Request) -> IronResult<GraphQlQuery> {
141+
fn handle_post(&self, req: &mut Request) -> IronResult<GraphQLQuery> {
142142
let mut request_payload = String::new();
143143
itry!(req.body.read_to_string(&mut request_payload));
144-
let graphql_query = serde_json::from_str::<GraphQlQuery>(request_payload.as_str()).map_err(|err|{
144+
let graphql_query = serde_json::from_str::<GraphQLQuery>(request_payload.as_str()).map_err(|err|{
145145
IronError::new(
146146
Box::new(GraphQlIronError::Serde(err)),
147147
(status::BadRequest, "No JSON object was decoded."))
148148
});
149149
graphql_query
150150
}
151151

152-
fn respond(&self, req: &mut Request, graphql: GraphQlQuery) -> IronResult<Response> {
152+
fn respond(&self, req: &mut Request, graphql: GraphQLQuery) -> IronResult<Response> {
153153
let context = (self.context_factory)(req);
154154
let variables = graphql.variables();
155155
let result = execute(graphql.query(),

src/integrations/serde.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ use serde::ser::SerializeMap;
33
use std::fmt;
44
use std::collections::HashMap;
55

6-
use ::{GraphQLError, Value};
7-
#[cfg(feature="iron-handlers")]
8-
use ::Variables;
6+
use ::{GraphQLError, Value, Variables};
97
use ast::InputValue;
108
use executor::ExecutionError;
119
use parser::{ParseError, Spanning, SourcePosition};
@@ -218,23 +216,20 @@ impl ser::Serialize for Value {
218216
}
219217

220218
/// The expected structure of the decoded JSON Document for either Post or Get requests.
221-
#[cfg(feature="iron-handlers")]
222219
#[derive(Deserialize)]
223-
pub struct GraphQlQuery {
220+
pub struct GraphQLQuery {
224221
query: String,
225222
#[serde(rename = "operationName")]
226223
operation_name: Option<String>,
227224
variables: Option<InputValue>
228225
}
229226

230-
#[cfg(feature="iron-handlers")]
231-
impl GraphQlQuery {
232-
227+
impl GraphQLQuery {
233228
pub fn new(query: String,
234229
operation_name: Option<String>,
235230
variables: Option<InputValue>
236-
) -> GraphQlQuery {
237-
GraphQlQuery {
231+
) -> GraphQLQuery {
232+
GraphQLQuery {
238233
query: query,
239234
operation_name: operation_name,
240235
variables: variables
@@ -260,10 +255,8 @@ impl GraphQlQuery {
260255
}
261256

262257

263-
#[cfg(feature="iron-handlers")]
264258
pub struct WrappedGraphQLResult<'a>(Result<(Value, Vec<ExecutionError>), GraphQLError<'a>>);
265259

266-
#[cfg(feature="iron-handlers")]
267260
impl<'a> WrappedGraphQLResult<'a> {
268261
pub fn new(result: Result<(Value, Vec<ExecutionError>),
269262
GraphQLError<'a>>
@@ -272,7 +265,6 @@ impl<'a> WrappedGraphQLResult<'a> {
272265
}
273266
}
274267

275-
#[cfg(feature="iron-handlers")]
276268
impl<'a> ser::Serialize for WrappedGraphQLResult<'a> {
277269
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
278270
where S: ser::Serializer,

src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ schema, as well as an optional integration into the [Iron framework][2]. It
1414
tries to keep the number of dynamic operations to a minimum, and give you as the
1515
schema developer the control of the query execution path.
1616
17-
Juniper only depends on `serde` and `serde_json` by default, making it lightweight and
18-
easy to drop into any project. Through the `iron-handlers` feature, it also
19-
depends on Iron.
17+
Juniper only depends on `serde` and `serde_derive` by default, making it
18+
lightweight and easy to drop into any project. Through the `iron-handlers`
19+
feature, it also depends on Iron.
2020
2121
## Exposing data types
2222
@@ -190,8 +190,9 @@ built-in [GraphiQL][6] handler included.
190190
#[cfg(feature="iron-handlers")] extern crate urlencoded;
191191
#[cfg(test)] extern crate iron_test;
192192
extern crate serde;
193-
extern crate serde_json;
194-
#[cfg(feature="iron-handlers")] #[macro_use] extern crate serde_derive;
193+
#[macro_use] extern crate serde_derive;
194+
195+
#[cfg(feature="iron-handlers")] extern crate serde_json;
195196

196197
#[macro_use] mod macros;
197198
mod ast;

0 commit comments

Comments
 (0)