commit
c51930aae5
2 changed files with 54 additions and 45 deletions
|
@ -23,7 +23,7 @@ expose-test-schema = []
|
|||
[dependencies]
|
||||
rustc-serialize = { version = "^0.3.19", optional = true }
|
||||
iron = { version = "^0.4.0", optional = true }
|
||||
serde = { version = "^0.8.21", optional = true }
|
||||
serde = { version = "^0.9.1", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
iron = "^0.4.0"
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use serde::{de, ser};
|
||||
use serde::ser::SerializeMap;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
|
||||
use ::{GraphQLError, Value};
|
||||
use ast::InputValue;
|
||||
|
@ -8,26 +10,27 @@ use parser::{ParseError, Spanning, SourcePosition};
|
|||
use validation::RuleError;
|
||||
|
||||
impl ser::Serialize for ExecutionError {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: ser::Serializer,
|
||||
{
|
||||
let mut state = try!(serializer.serialize_map(Some(3)));
|
||||
let mut map = try!(serializer.serialize_map(Some(3)));
|
||||
|
||||
try!(serializer.serialize_map_key(&mut state, "message"));
|
||||
try!(serializer.serialize_map_value(&mut state, self.message()));
|
||||
try!(map.serialize_key("message"));
|
||||
try!(map.serialize_value(self.message()));
|
||||
|
||||
try!(serializer.serialize_map_key(&mut state, "locations"));
|
||||
try!(serializer.serialize_map_value(&mut state, vec![self.location()]));
|
||||
let locations = vec![self.location()];
|
||||
try!(map.serialize_key("locations"));
|
||||
try!(map.serialize_value(&locations));
|
||||
|
||||
try!(serializer.serialize_map_key(&mut state, "path"));
|
||||
try!(serializer.serialize_map_value(&mut state, self.path()));
|
||||
try!(map.serialize_key("path"));
|
||||
try!(map.serialize_value(self.path()));
|
||||
|
||||
serializer.serialize_map_end(state)
|
||||
map.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ser::Serialize for GraphQLError<'a> {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: ser::Serializer,
|
||||
{
|
||||
match *self {
|
||||
|
@ -47,7 +50,7 @@ impl<'a> ser::Serialize for GraphQLError<'a> {
|
|||
}
|
||||
|
||||
impl de::Deserialize for InputValue {
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<InputValue, D::Error>
|
||||
fn deserialize<D>(deserializer: D) -> Result<InputValue, D::Error>
|
||||
where D: de::Deserializer,
|
||||
{
|
||||
struct InputValueVisitor;
|
||||
|
@ -55,50 +58,54 @@ impl de::Deserialize for InputValue {
|
|||
impl de::Visitor for InputValueVisitor {
|
||||
type Value = InputValue;
|
||||
|
||||
fn visit_bool<E>(&mut self, value: bool) -> Result<InputValue, E> {
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("a valid input value")
|
||||
}
|
||||
|
||||
fn visit_bool<E>(self, value: bool) -> Result<InputValue, E> {
|
||||
Ok(InputValue::boolean(value))
|
||||
}
|
||||
|
||||
fn visit_i64<E>(&mut self, value: i64) -> Result<InputValue, E> {
|
||||
fn visit_i64<E>(self, value: i64) -> Result<InputValue, E> {
|
||||
Ok(InputValue::int(value))
|
||||
}
|
||||
|
||||
fn visit_u64<E>(&mut self, value: u64) -> Result<InputValue, E>
|
||||
fn visit_u64<E>(self, value: u64) -> Result<InputValue, E>
|
||||
where E: de::Error,
|
||||
{
|
||||
self.visit_f64(value as f64)
|
||||
}
|
||||
|
||||
fn visit_f64<E>(&mut self, value: f64) -> Result<InputValue, E> {
|
||||
fn visit_f64<E>(self, value: f64) -> Result<InputValue, E> {
|
||||
Ok(InputValue::float(value))
|
||||
}
|
||||
|
||||
fn visit_str<E>(&mut self, value: &str) -> Result<InputValue, E>
|
||||
fn visit_str<E>(self, value: &str) -> Result<InputValue, E>
|
||||
where E: de::Error,
|
||||
{
|
||||
self.visit_string(value.into())
|
||||
}
|
||||
|
||||
fn visit_string<E>(&mut self, value: String) -> Result<InputValue, E> {
|
||||
fn visit_string<E>(self, value: String) -> Result<InputValue, E> {
|
||||
Ok(InputValue::string(value))
|
||||
}
|
||||
|
||||
fn visit_none<E>(&mut self) -> Result<InputValue, E> {
|
||||
fn visit_none<E>(self) -> Result<InputValue, E> {
|
||||
Ok(InputValue::null())
|
||||
}
|
||||
|
||||
fn visit_unit<E>(&mut self) -> Result<InputValue, E> {
|
||||
fn visit_unit<E>(self) -> Result<InputValue, E> {
|
||||
Ok(InputValue::null())
|
||||
}
|
||||
|
||||
fn visit_seq<V>(&mut self, visitor: V) -> Result<InputValue, V::Error>
|
||||
fn visit_seq<V>(self, visitor: V) -> Result<InputValue, V::Error>
|
||||
where V: de::SeqVisitor,
|
||||
{
|
||||
let values = try!(de::impls::VecVisitor::new().visit_seq(visitor));
|
||||
Ok(InputValue::list(values))
|
||||
}
|
||||
|
||||
fn visit_map<V>(&mut self, visitor: V) -> Result<InputValue, V::Error>
|
||||
fn visit_map<V>(self, visitor: V) -> Result<InputValue, V::Error>
|
||||
where V: de::MapVisitor,
|
||||
{
|
||||
let values = try!(de::impls::HashMapVisitor::<String, InputValue, _>::new()
|
||||
|
@ -112,7 +119,7 @@ impl de::Deserialize for InputValue {
|
|||
}
|
||||
|
||||
impl ser::Serialize for InputValue {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: ser::Serializer,
|
||||
{
|
||||
match *self {
|
||||
|
@ -135,46 +142,48 @@ impl ser::Serialize for InputValue {
|
|||
}
|
||||
|
||||
impl ser::Serialize for RuleError {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: ser::Serializer,
|
||||
{
|
||||
let mut state = try!(serializer.serialize_map(Some(2)));
|
||||
let mut map = try!(serializer.serialize_map(Some(2)));
|
||||
|
||||
try!(serializer.serialize_map_key(&mut state, "message"));
|
||||
try!(serializer.serialize_map_value(&mut state, self.message()));
|
||||
try!(map.serialize_key("message"));
|
||||
try!(map.serialize_value(self.message()));
|
||||
|
||||
try!(serializer.serialize_map_key(&mut state, "locations"));
|
||||
try!(serializer.serialize_map_value(&mut state, self.locations()));
|
||||
try!(map.serialize_key("locations"));
|
||||
try!(map.serialize_value(self.locations()));
|
||||
|
||||
serializer.serialize_map_end(state)
|
||||
map.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl ser::Serialize for SourcePosition {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: ser::Serializer,
|
||||
{
|
||||
let mut state = try!(serializer.serialize_map(Some(2)));
|
||||
let mut map = try!(serializer.serialize_map(Some(2)));
|
||||
|
||||
try!(serializer.serialize_map_key(&mut state, "line"));
|
||||
try!(serializer.serialize_map_value(&mut state, self.line() + 1));
|
||||
let line = self.line() + 1;
|
||||
try!(map.serialize_key("line"));
|
||||
try!(map.serialize_value(&line));
|
||||
|
||||
try!(serializer.serialize_map_key(&mut state, "column"));
|
||||
try!(serializer.serialize_map_value(&mut state, self.column() + 1));
|
||||
let column = self.column() + 1;
|
||||
try!(map.serialize_key("column"));
|
||||
try!(map.serialize_value(&column));
|
||||
|
||||
serializer.serialize_map_end(state)
|
||||
map.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ser::Serialize for Spanning<ParseError<'a>> {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: ser::Serializer,
|
||||
{
|
||||
let mut state = try!(serializer.serialize_map(Some(2)));
|
||||
let mut map = try!(serializer.serialize_map(Some(2)));
|
||||
|
||||
let message = format!("{}", self.item);
|
||||
try!(serializer.serialize_map_key(&mut state, "message"));
|
||||
try!(serializer.serialize_map_value(&mut state, message));
|
||||
try!(map.serialize_key("message"));
|
||||
try!(map.serialize_value(&message));
|
||||
|
||||
let mut location = HashMap::new();
|
||||
location.insert("line".to_owned(), self.start.line() + 1);
|
||||
|
@ -182,15 +191,15 @@ impl<'a> ser::Serialize for Spanning<ParseError<'a>> {
|
|||
|
||||
let locations = vec![location];
|
||||
|
||||
try!(serializer.serialize_map_key(&mut state, "locations"));
|
||||
try!(serializer.serialize_map_value(&mut state, locations));
|
||||
try!(map.serialize_key("locations"));
|
||||
try!(map.serialize_value(&locations));
|
||||
|
||||
serializer.serialize_map_end(state)
|
||||
map.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl ser::Serialize for Value {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: ser::Serializer,
|
||||
{
|
||||
match *self {
|
||||
|
|
Loading…
Reference in a new issue