(ci) Check formatting with cargo fmt (#302)

This adds a new extra CI job for checking the formatting
with cargo fmt --check.
This commit is contained in:
theduke 2018-12-19 19:27:49 +01:00 committed by Christian Legnitto
parent aa80ec51bb
commit d015a3ca66
74 changed files with 1903 additions and 1684 deletions

View file

@ -1,14 +1,27 @@
jobs:
- template: _build/azure-pipelines-template.yml
parameters:
name: macOS
vmImage: macOS-10.13
- job: check_formatting
pool:
vmImage: ubuntu-16.04
steps:
- script: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
$HOME/.cargo/bin/rustup component add rustfmt
displayName: Install rust
- script: |
$HOME/.cargo/bin/cargo fmt -- --check
displayName: Check formatting
- template: _build/azure-pipelines-template.yml
parameters:
name: Linux
vmImage: ubuntu-16.04
- template: _build/azure-pipelines-template.yml
parameters:
name: macOS
vmImage: macOS-10.13
- template: _build/azure-pipelines-template.yml
parameters:
name: Windows

View file

@ -31,6 +31,4 @@ juniper::graphql_object!(Query: () |&self| {
}
});
fn main() {
}
fn main() {}

View file

@ -8,11 +8,7 @@ use juniper::{self, DefaultScalarValue, FromInputValue, GraphQLType, InputValue,
#[graphql(name = "Some", description = "enum descr")]
enum SomeEnum {
Regular,
#[graphql(
name = "FULL",
description = "field descr",
deprecated = "depr"
)]
#[graphql(name = "FULL", description = "field descr", deprecated = "depr")]
Full,
}

View file

@ -105,7 +105,8 @@ fn test_derived_input_object() {
let input_no_defaults: InputValue = ::serde_json::from_value(json!({
"regularField": "a",
})).unwrap();
}))
.unwrap();
let output_no_defaults: Input = FromInputValue::from_input_value(&input_no_defaults).unwrap();
assert_eq!(
@ -123,7 +124,8 @@ fn test_derived_input_object() {
"regularField": "a",
"haha": 55,
"other": true,
})).unwrap();
}))
.unwrap();
let output: Input = FromInputValue::from_input_value(&input).unwrap();
assert_eq!(

View file

@ -189,10 +189,12 @@ fn test_derived_object() {
vec![
("regularField", Value::scalar(true)),
("renamedField", Value::scalar(22)),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]
@ -252,13 +254,16 @@ fn test_derived_object_nested() {
vec![
("regularField", Value::scalar(false)),
("renamedField", Value::scalar(333)),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]
@ -297,15 +302,14 @@ fn check_descriptions(
type_info.get_field_value("description"),
Some(object_description)
);
assert!(
values.contains(&Value::object(
vec![
("name", Value::scalar(field_name)),
("description", field_value.clone()),
].into_iter()
.collect(),
))
);
assert!(values.contains(&Value::object(
vec![
("name", Value::scalar(field_name)),
("description", field_value.clone()),
]
.into_iter()
.collect(),
)));
});
}

View file

@ -220,7 +220,8 @@ fn querying_long_variable() {
vec![(
"test".to_owned(),
InputValue::Scalar(MyScalarValue::Long((::std::i32::MAX as i64) + 42)),
)].into_iter()
)]
.into_iter()
.collect(),
|result| {
assert_eq!(

View file

@ -8,7 +8,7 @@ use indexmap::IndexMap;
use executor::Variables;
use parser::Spanning;
use value::{ScalarRefValue, ScalarValue, DefaultScalarValue};
use value::{DefaultScalarValue, ScalarRefValue, ScalarValue};
/// A type literal in the syntax tree
///
@ -285,7 +285,8 @@ where
Spanning::unlocated(k.as_ref().to_owned()),
Spanning::unlocated(v),
)
}).collect(),
})
.collect(),
)
}
@ -346,10 +347,7 @@ where
}
/// View the underlying int value, if present.
#[deprecated(
since = "0.11.0",
note = "Use `InputValue::as_scalar_value` instead"
)]
#[deprecated(since = "0.11.0", note = "Use `InputValue::as_scalar_value` instead")]
pub fn as_int_value<'a>(&'a self) -> Option<i32>
where
&'a S: Into<Option<&'a i32>>,
@ -358,10 +356,7 @@ where
}
/// View the underlying float value, if present.
#[deprecated(
since = "0.11.0",
note = "Use `InputValue::as_scalar_value` instead"
)]
#[deprecated(since = "0.11.0", note = "Use `InputValue::as_scalar_value` instead")]
pub fn as_float_value<'a>(&'a self) -> Option<f64>
where
&'a S: Into<Option<&'a f64>>,
@ -370,10 +365,7 @@ where
}
/// View the underlying string value, if present.
#[deprecated(
since = "0.11.0",
note = "Use `InputValue::as_scalar_value` instead"
)]
#[deprecated(since = "0.11.0", note = "Use `InputValue::as_scalar_value` instead")]
pub fn as_string_value<'a>(&'a self) -> Option<&'a str>
where
&'a S: Into<Option<&'a String>>,
@ -453,11 +445,12 @@ where
.zip(l2.iter())
.all(|(v1, v2)| v1.item.unlocated_eq(&v2.item)),
(&Object(ref o1), &Object(ref o2)) => {
o1.len() == o2.len() && o1.iter().all(|&(ref sk1, ref sv1)| {
o2.iter().any(|&(ref sk2, ref sv2)| {
sk1.item == sk2.item && sv1.item.unlocated_eq(&sv2.item)
o1.len() == o2.len()
&& o1.iter().all(|&(ref sk1, ref sv1)| {
o2.iter().any(|&(ref sk2, ref sv2)| {
sk1.item == sk2.item && sv1.item.unlocated_eq(&sv2.item)
})
})
})
}
_ => false,
}

View file

@ -52,7 +52,8 @@ where
&n.item as &str,
LookAheadValue::from_input_value(&i.item, vars),
)
}).collect(),
})
.collect(),
),
}
}
@ -134,7 +135,8 @@ where
} else {
false
}
}).unwrap_or(false),
})
.unwrap_or(false),
("skip", &Some(ref a)) => a
.item
.items
@ -150,13 +152,15 @@ where
} else {
false
}
}).unwrap_or(false),
})
.unwrap_or(false),
("skip", &None) => false,
("include", &None) => true,
(_, _) => unreachable!(),
}
})
}).unwrap_or(true)
})
.unwrap_or(true)
}
pub(super) fn build_from_selection(
@ -192,7 +196,8 @@ where
.iter()
.map(|p| LookAheadArgument::new(p, vars))
.collect()
}).unwrap_or_else(Vec::new);
})
.unwrap_or_else(Vec::new);
let mut ret = LookAheadSelection {
name,
alias,
@ -280,7 +285,8 @@ where
}
Applies::All => Some(c.inner.for_explicit_type(type_name)),
Applies::OnlyType(_) => None,
}).collect(),
})
.collect(),
name: self.name,
alias: self.alias,
arguments: self.arguments.clone(),
@ -390,7 +396,8 @@ query Hero {
}
}
",
).unwrap();
)
.unwrap();
let fragments = extract_fragments(&docs);
if let ::ast::Definition::Operation(ref op) = docs[0] {
@ -442,7 +449,8 @@ query Hero {
}
}
",
).unwrap();
)
.unwrap();
let fragments = extract_fragments(&docs);
if let ::ast::Definition::Operation(ref op) = docs[0] {
@ -498,7 +506,8 @@ query Hero {
}
}
",
).unwrap();
)
.unwrap();
let fragments = extract_fragments(&docs);
if let ::ast::Definition::Operation(ref op) = docs[0] {
@ -578,7 +587,8 @@ query Hero {
}
}
",
).unwrap();
)
.unwrap();
let fragments = extract_fragments(&docs);
if let ::ast::Definition::Operation(ref op) = docs[0] {
@ -636,7 +646,8 @@ query Hero($episode: Episode) {
}
}
",
).unwrap();
)
.unwrap();
let fragments = extract_fragments(&docs);
if let ::ast::Definition::Operation(ref op) = docs[0] {
@ -697,7 +708,8 @@ fragment commonFields on Character {
appearsIn
}
",
).unwrap();
)
.unwrap();
let fragments = extract_fragments(&docs);
if let ::ast::Definition::Operation(ref op) = docs[0] {
@ -759,7 +771,8 @@ query Hero {
height @skip(if: false)
}
}",
).unwrap();
)
.unwrap();
let fragments = extract_fragments(&docs);
if let ::ast::Definition::Operation(ref op) = docs[0] {
@ -815,7 +828,8 @@ query Hero {
}
}
}",
).unwrap();
)
.unwrap();
let fragments = extract_fragments(&docs);
if let ::ast::Definition::Operation(ref op) = docs[0] {
@ -887,7 +901,8 @@ fragment comparisonFields on Character {
... on Droid { primaryFunction }
... on Human { height }
}",
).unwrap();
)
.unwrap();
let fragments = extract_fragments(&docs);
if let ::ast::Definition::Operation(ref op) = docs[0] {
@ -1043,7 +1058,8 @@ query Hero {
}
}
}",
).unwrap();
)
.unwrap();
let fragments = extract_fragments(&docs);
if let ::ast::Definition::Operation(ref op) = docs[0] {
@ -1052,7 +1068,8 @@ query Hero {
&op.item.selection_set[0],
&vars,
&fragments,
).for_explicit_type("Human");
)
.for_explicit_type("Human");
let expected = ConcreteLookAheadSelection {
name: "hero",
alias: None,

View file

@ -515,7 +515,8 @@ where
self.parent_selection_set
.map(|p| {
LookAheadSelection::build_from_selection(&p[0], self.variables, self.fragments)
}).unwrap_or_else(|| LookAheadSelection {
})
.unwrap_or_else(|| LookAheadSelection {
name: self.current_type.innermost_concrete().name().unwrap_or(""),
alias: None,
arguments: Vec::new(),
@ -530,8 +531,10 @@ where
self.fragments,
),
applies_for: Applies::All,
}).collect()
}).unwrap_or_else(Vec::new),
})
.collect()
})
.unwrap_or_else(Vec::new),
})
}
}
@ -627,7 +630,8 @@ where
def.default_value
.as_ref()
.map(|i| (name.item.to_owned(), i.item.clone()))
}).collect::<HashMap<String, InputValue<S>>>()
})
.collect::<HashMap<String, InputValue<S>>>()
});
let errors = RwLock::new(Vec::new());

View file

@ -1,7 +1,7 @@
use executor::Variables;
use schema::model::RootNode;
use types::scalars::EmptyMutation;
use value::{Value, Object, DefaultScalarValue};
use value::{DefaultScalarValue, Object, Value};
struct TestType;

View file

@ -103,7 +103,8 @@ mod field_execution {
vec![
("a", Value::scalar("Apple")),
("b", Value::scalar("Banana")),
].into_iter()
]
.into_iter()
.collect(),
),
Value::null(),
@ -111,16 +112,19 @@ mod field_execution {
vec![
("a", Value::scalar("Apple")),
("b", Value::scalar("Banana")),
].into_iter()
]
.into_iter()
.collect(),
),
]),
),
].into_iter()
]
.into_iter()
.collect(),
),
),
].into_iter()
]
.into_iter()
.collect()
)
);
@ -180,17 +184,20 @@ mod merge_parallel_fragments {
vec![
("b", Value::scalar("Banana")),
("c", Value::scalar("Cherry")),
].into_iter()
]
.into_iter()
.collect(),
),
),
("c", Value::scalar("Cherry")),
].into_iter()
]
.into_iter()
.collect(),
),
),
("c", Value::scalar("Cherry")),
].into_iter()
]
.into_iter()
.collect()
)
);
@ -278,10 +285,12 @@ mod merge_parallel_inline_fragments {
vec![
("b", Value::scalar("Banana")),
("c", Value::scalar("Cherry")),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect(),
),
Value::object(
@ -291,21 +300,25 @@ mod merge_parallel_inline_fragments {
vec![
("b", Value::scalar("Banana")),
("c", Value::scalar("Cherry")),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect(),
),
]),
),
("c", Value::scalar("Cherry")),
].into_iter()
]
.into_iter()
.collect(),
),
),
("c", Value::scalar("Cherry")),
].into_iter()
]
.into_iter()
.collect()
)
);
@ -345,7 +358,8 @@ mod threads_context_correctly {
&TestContext {
value: "Context value".to_owned(),
},
).expect("Execution failed");
)
.expect("Execution failed");
assert_eq!(errs, []);
@ -438,7 +452,8 @@ mod dynamic_context_switching {
value: "Second value".to_owned(),
},
),
].into_iter()
]
.into_iter()
.collect(),
};
@ -461,7 +476,8 @@ mod dynamic_context_switching {
),
),
("missing", Value::null()),
].into_iter()
]
.into_iter()
.collect()
)
);
@ -492,7 +508,8 @@ mod dynamic_context_switching {
value: "Second value".to_owned(),
},
),
].into_iter()
]
.into_iter()
.collect(),
};
@ -512,7 +529,8 @@ mod dynamic_context_switching {
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
)
);
@ -543,7 +561,8 @@ mod dynamic_context_switching {
value: "Second value".to_owned(),
},
),
].into_iter()
]
.into_iter()
.collect(),
};
@ -590,7 +609,8 @@ mod dynamic_context_switching {
value: "Second value".to_owned(),
},
),
].into_iter()
]
.into_iter()
.collect(),
};
@ -621,7 +641,8 @@ mod dynamic_context_switching {
),
("missing", Value::null()),
("tooLarge", Value::null()),
].into_iter()
]
.into_iter()
.collect()
)
);
@ -648,7 +669,8 @@ mod dynamic_context_switching {
value: "Second value".to_owned(),
},
),
].into_iter()
]
.into_iter()
.collect(),
};
@ -668,7 +690,8 @@ mod dynamic_context_switching {
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
)
);

View file

@ -123,18 +123,21 @@ mod interface {
vec![
("name", Value::scalar("Odie")),
("woofs", Value::scalar(true)),
].into_iter()
]
.into_iter()
.collect(),
),
Value::object(
vec![
("name", Value::scalar("Garfield")),
("meows", Value::scalar(false)),
].into_iter()
]
.into_iter()
.collect(),
),
]),
)].into_iter()
)]
.into_iter()
.collect()
)
);
@ -255,7 +258,8 @@ mod union {
("__typename", Value::scalar("Dog")),
("name", Value::scalar("Odie")),
("woofs", Value::scalar(true)),
].into_iter()
]
.into_iter()
.collect(),
),
Value::object(
@ -263,11 +267,13 @@ mod union {
("__typename", Value::scalar("Cat")),
("name", Value::scalar("Garfield")),
("meows", Value::scalar(false)),
].into_iter()
]
.into_iter()
.collect(),
),
]),
)].into_iter()
)]
.into_iter()
.collect()
)
);

View file

@ -1,7 +1,7 @@
use executor::Variables;
use schema::model::RootNode;
use types::scalars::EmptyMutation;
use value::{Value, Object, DefaultScalarValue};
use value::{DefaultScalarValue, Object, Value};
/*
@ -53,7 +53,10 @@ enum EnumValueDescription {
enum EnumDeprecation {
#[graphql(deprecated = "Please don't use FOO any more")]
Foo,
#[graphql(description = "The BAR value", deprecated = "Please don't use BAR any more")]
#[graphql(
description = "The BAR value",
deprecated = "Please don't use BAR any more"
)]
Bar,
}
@ -116,34 +119,38 @@ fn default_name_introspection() {
"#;
run_type_info_query(doc, |(type_info, values)| {
assert_eq!(type_info.get_field_value("name"), Some(&Value::scalar("DefaultName")));
assert_eq!(type_info.get_field_value("description"), Some(&Value::null()));
assert_eq!(
type_info.get_field_value("name"),
Some(&Value::scalar("DefaultName"))
);
assert_eq!(
type_info.get_field_value("description"),
Some(&Value::null())
);
assert_eq!(values.len(), 2);
assert!(
values.contains(&Value::object(
vec![
("name", Value::scalar("FOO")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
].into_iter()
.collect(),
))
);
assert!(values.contains(&Value::object(
vec![
("name", Value::scalar("FOO")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
]
.into_iter()
.collect(),
)));
assert!(
values.contains(&Value::object(
vec![
("name", Value::scalar("BAR")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
].into_iter()
.collect(),
))
);
assert!(values.contains(&Value::object(
vec![
("name", Value::scalar("BAR")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
]
.into_iter()
.collect(),
)));
});
}
@ -165,34 +172,38 @@ fn named_introspection() {
"#;
run_type_info_query(doc, |(type_info, values)| {
assert_eq!(type_info.get_field_value("name"), Some(&Value::scalar("ANamedEnum")));
assert_eq!(type_info.get_field_value("description"), Some(&Value::null()));
assert_eq!(
type_info.get_field_value("name"),
Some(&Value::scalar("ANamedEnum"))
);
assert_eq!(
type_info.get_field_value("description"),
Some(&Value::null())
);
assert_eq!(values.len(), 2);
assert!(
values.contains(&Value::object(
vec![
("name", Value::scalar("FOO")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
].into_iter()
.collect(),
))
);
assert!(values.contains(&Value::object(
vec![
("name", Value::scalar("FOO")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
]
.into_iter()
.collect(),
)));
assert!(
values.contains(&Value::object(
vec![
("name", Value::scalar("BAR")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
].into_iter()
.collect(),
))
);
assert!(values.contains(&Value::object(
vec![
("name", Value::scalar("BAR")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
]
.into_iter()
.collect(),
)));
});
}
@ -218,33 +229,34 @@ fn no_trailing_comma_introspection() {
type_info.get_field_value("name"),
Some(&Value::scalar("NoTrailingComma"))
);
assert_eq!(type_info.get_field_value("description"), Some(&Value::null()));
assert_eq!(
type_info.get_field_value("description"),
Some(&Value::null())
);
assert_eq!(values.len(), 2);
assert!(
values.contains(&Value::object(
vec![
("name", Value::scalar("FOO")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
].into_iter()
.collect(),
))
);
assert!(values.contains(&Value::object(
vec![
("name", Value::scalar("FOO")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
]
.into_iter()
.collect(),
)));
assert!(
values.contains(&Value::object(
vec![
("name", Value::scalar("BAR")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
].into_iter()
.collect(),
))
);
assert!(values.contains(&Value::object(
vec![
("name", Value::scalar("BAR")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
]
.into_iter()
.collect(),
)));
});
}
@ -277,29 +289,27 @@ fn enum_description_introspection() {
assert_eq!(values.len(), 2);
assert!(
values.contains(&Value::object(
vec![
("name", Value::scalar("FOO")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
].into_iter()
.collect(),
))
);
assert!(values.contains(&Value::object(
vec![
("name", Value::scalar("FOO")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
]
.into_iter()
.collect(),
)));
assert!(
values.contains(&Value::object(
vec![
("name", Value::scalar("BAR")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
].into_iter()
.collect(),
))
);
assert!(values.contains(&Value::object(
vec![
("name", Value::scalar("BAR")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
]
.into_iter()
.collect(),
)));
});
}
@ -325,33 +335,34 @@ fn enum_value_description_introspection() {
type_info.get_field_value("name"),
Some(&Value::scalar("EnumValueDescription"))
);
assert_eq!(type_info.get_field_value("description"), Some(&Value::null()));
assert_eq!(
type_info.get_field_value("description"),
Some(&Value::null())
);
assert_eq!(values.len(), 2);
assert!(
values.contains(&Value::object(
vec![
("name", Value::scalar("FOO")),
("description", Value::scalar("The FOO value")),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
].into_iter()
.collect(),
))
);
assert!(values.contains(&Value::object(
vec![
("name", Value::scalar("FOO")),
("description", Value::scalar("The FOO value")),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
]
.into_iter()
.collect(),
)));
assert!(
values.contains(&Value::object(
vec![
("name", Value::scalar("BAR")),
("description", Value::scalar("The BAR value")),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
].into_iter()
.collect(),
))
);
assert!(values.contains(&Value::object(
vec![
("name", Value::scalar("BAR")),
("description", Value::scalar("The BAR value")),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
]
.into_iter()
.collect(),
)));
});
}
@ -377,39 +388,40 @@ fn enum_deprecation_introspection() {
type_info.get_field_value("name"),
Some(&Value::scalar("EnumDeprecation"))
);
assert_eq!(type_info.get_field_value("description"), Some(&Value::null()));
assert_eq!(
type_info.get_field_value("description"),
Some(&Value::null())
);
assert_eq!(values.len(), 2);
assert!(
values.contains(&Value::object(
vec![
("name", Value::scalar("FOO")),
("description", Value::null()),
("isDeprecated", Value::scalar(true)),
(
"deprecationReason",
Value::scalar("Please don't use FOO any more"),
),
].into_iter()
.collect(),
))
);
assert!(values.contains(&Value::object(
vec![
("name", Value::scalar("FOO")),
("description", Value::null()),
("isDeprecated", Value::scalar(true)),
(
"deprecationReason",
Value::scalar("Please don't use FOO any more"),
),
]
.into_iter()
.collect(),
)));
assert!(
values.contains(&Value::object(
vec![
("name", Value::scalar("BAR")),
("description", Value::scalar("The BAR value")),
("isDeprecated", Value::scalar(true)),
(
"deprecationReason",
Value::scalar("Please don't use BAR any more"),
),
].into_iter()
.collect(),
))
);
assert!(values.contains(&Value::object(
vec![
("name", Value::scalar("BAR")),
("description", Value::scalar("The BAR value")),
("isDeprecated", Value::scalar(true)),
(
"deprecationReason",
Value::scalar("Please don't use BAR any more"),
),
]
.into_iter()
.collect(),
)));
});
}
@ -435,7 +447,10 @@ fn enum_deprecation_no_values_introspection() {
type_info.get_field_value("name"),
Some(&Value::scalar("EnumDeprecation"))
);
assert_eq!(type_info.get_field_value("description"), Some(&Value::null()));
assert_eq!(
type_info.get_field_value("description"),
Some(&Value::null())
);
assert_eq!(values.len(), 0);
});

View file

@ -49,7 +49,7 @@ pub struct PublicWithDescription {
#[derive(GraphQLInputObjectInternal, Debug)]
#[graphql(
name = "APublicNamedInputObjectWithDescription",
description = "Description for the input object",
description = "Description for the input object"
)]
pub struct NamedPublicWithDescription {
field_one: String,
@ -158,55 +158,55 @@ fn default_name_introspection() {
assert_eq!(fields.len(), 2);
assert!(
fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldOne")),
("description", Value::null()),
(
"type",
Value::object(
vec![(
"ofType",
Value::object(
vec![("name", Value::scalar("String"))]
.into_iter()
.collect(),
),
)].into_iter()
.collect(),
),
assert!(fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldOne")),
("description", Value::null()),
(
"type",
Value::object(
vec![(
"ofType",
Value::object(
vec![("name", Value::scalar("String"))]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect(),
),
("defaultValue", Value::null()),
].into_iter()
.collect(),
))
);
),
("defaultValue", Value::null()),
]
.into_iter()
.collect(),
)));
assert!(
fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldTwo")),
("description", Value::null()),
(
"type",
Value::object(
vec![(
"ofType",
Value::object(
vec![("name", Value::scalar("String"))]
.into_iter()
.collect(),
),
)].into_iter()
.collect(),
),
assert!(fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldTwo")),
("description", Value::null()),
(
"type",
Value::object(
vec![(
"ofType",
Value::object(
vec![("name", Value::scalar("String"))]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect(),
),
("defaultValue", Value::null()),
].into_iter()
.collect(),
))
);
),
("defaultValue", Value::null()),
]
.into_iter()
.collect(),
)));
});
}
@ -216,7 +216,8 @@ fn default_name_input_value() {
vec![
("fieldOne", InputValue::scalar("number one")),
("fieldTwo", InputValue::scalar("number two")),
].into_iter()
]
.into_iter()
.collect(),
);
@ -263,55 +264,55 @@ fn no_trailing_comma_introspection() {
assert_eq!(fields.len(), 2);
assert!(
fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldOne")),
("description", Value::null()),
(
"type",
Value::object(
vec![(
"ofType",
Value::object(
vec![("name", Value::scalar("String"))]
.into_iter()
.collect(),
),
)].into_iter()
.collect(),
),
assert!(fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldOne")),
("description", Value::null()),
(
"type",
Value::object(
vec![(
"ofType",
Value::object(
vec![("name", Value::scalar("String"))]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect(),
),
("defaultValue", Value::null()),
].into_iter()
.collect(),
))
);
),
("defaultValue", Value::null()),
]
.into_iter()
.collect(),
)));
assert!(
fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldTwo")),
("description", Value::null()),
(
"type",
Value::object(
vec![(
"ofType",
Value::object(
vec![("name", Value::scalar("String"))]
.into_iter()
.collect(),
),
)].into_iter()
.collect(),
),
assert!(fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldTwo")),
("description", Value::null()),
(
"type",
Value::object(
vec![(
"ofType",
Value::object(
vec![("name", Value::scalar("String"))]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect(),
),
("defaultValue", Value::null()),
].into_iter()
.collect(),
))
);
),
("defaultValue", Value::null()),
]
.into_iter()
.collect(),
)));
});
}
@ -348,30 +349,30 @@ fn derive_introspection() {
assert_eq!(fields.len(), 1);
assert!(
fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldOne")),
("description", Value::null()),
(
"type",
Value::object(
vec![(
"ofType",
Value::object(
vec![("name", Value::scalar("String"))]
.into_iter()
.collect(),
),
)].into_iter()
.collect(),
),
assert!(fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldOne")),
("description", Value::null()),
(
"type",
Value::object(
vec![(
"ofType",
Value::object(
vec![("name", Value::scalar("String"))]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect(),
),
("defaultValue", Value::null()),
].into_iter()
.collect(),
))
);
),
("defaultValue", Value::null()),
]
.into_iter()
.collect(),
)));
});
}
@ -421,30 +422,30 @@ fn named_introspection() {
assert_eq!(fields.len(), 1);
assert!(
fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldOne")),
("description", Value::null()),
(
"type",
Value::object(
vec![(
"ofType",
Value::object(
vec![("name", Value::scalar("String"))]
.into_iter()
.collect(),
),
)].into_iter()
.collect(),
),
assert!(fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldOne")),
("description", Value::null()),
(
"type",
Value::object(
vec![(
"ofType",
Value::object(
vec![("name", Value::scalar("String"))]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect(),
),
("defaultValue", Value::null()),
].into_iter()
.collect(),
))
);
),
("defaultValue", Value::null()),
]
.into_iter()
.collect(),
)));
});
}
@ -481,30 +482,30 @@ fn description_introspection() {
assert_eq!(fields.len(), 1);
assert!(
fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldOne")),
("description", Value::null()),
(
"type",
Value::object(
vec![(
"ofType",
Value::object(
vec![("name", Value::scalar("String"))]
.into_iter()
.collect(),
),
)].into_iter()
.collect(),
),
assert!(fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldOne")),
("description", Value::null()),
(
"type",
Value::object(
vec![(
"ofType",
Value::object(
vec![("name", Value::scalar("String"))]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect(),
),
("defaultValue", Value::null()),
].into_iter()
.collect(),
))
);
),
("defaultValue", Value::null()),
]
.into_iter()
.collect(),
)));
});
}
@ -541,55 +542,55 @@ fn field_description_introspection() {
assert_eq!(fields.len(), 2);
assert!(
fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldOne")),
("description", Value::scalar("The first field")),
(
"type",
Value::object(
vec![(
"ofType",
Value::object(
vec![("name", Value::scalar("String"))]
.into_iter()
.collect(),
),
)].into_iter()
.collect(),
),
assert!(fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldOne")),
("description", Value::scalar("The first field")),
(
"type",
Value::object(
vec![(
"ofType",
Value::object(
vec![("name", Value::scalar("String"))]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect(),
),
("defaultValue", Value::null()),
].into_iter()
.collect(),
))
);
),
("defaultValue", Value::null()),
]
.into_iter()
.collect(),
)));
assert!(
fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldTwo")),
("description", Value::scalar("The second field")),
(
"type",
Value::object(
vec![(
"ofType",
Value::object(
vec![("name", Value::scalar("String"))]
.into_iter()
.collect(),
),
)].into_iter()
.collect(),
),
assert!(fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldTwo")),
("description", Value::scalar("The second field")),
(
"type",
Value::object(
vec![(
"ofType",
Value::object(
vec![("name", Value::scalar("String"))]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect(),
),
("defaultValue", Value::null()),
].into_iter()
.collect(),
))
);
),
("defaultValue", Value::null()),
]
.into_iter()
.collect(),
)));
});
}
@ -618,32 +619,30 @@ fn field_with_defaults_introspection() {
assert_eq!(fields.len(), 2);
assert!(
fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldOne")),
(
"type",
Value::object(vec![("name", Value::scalar("Int"))].into_iter().collect()),
),
("defaultValue", Value::scalar("123")),
].into_iter()
.collect(),
))
);
assert!(fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldOne")),
(
"type",
Value::object(vec![("name", Value::scalar("Int"))].into_iter().collect()),
),
("defaultValue", Value::scalar("123")),
]
.into_iter()
.collect(),
)));
assert!(
fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldTwo")),
(
"type",
Value::object(vec![("name", Value::scalar("Int"))].into_iter().collect()),
),
("defaultValue", Value::scalar("456")),
].into_iter()
.collect(),
))
);
assert!(fields.contains(&Value::object(
vec![
("name", Value::scalar("fieldTwo")),
(
"type",
Value::object(vec![("name", Value::scalar("Int"))].into_iter().collect()),
),
("defaultValue", Value::scalar("456")),
]
.into_iter()
.collect(),
)));
});
}

View file

@ -91,7 +91,8 @@ fn test_execution() {
("sampleEnum", Value::scalar("ONE")),
("first", Value::scalar(123)),
("second", Value::scalar(30)),
].into_iter()
]
.into_iter()
.collect()
)
);
@ -169,29 +170,27 @@ fn enum_introspection() {
assert_eq!(values.len(), 2);
assert!(
values.contains(&Value::object(
vec![
("name", Value::scalar("ONE")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
].into_iter()
.collect(),
))
);
assert!(values.contains(&Value::object(
vec![
("name", Value::scalar("ONE")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
]
.into_iter()
.collect(),
)));
assert!(
values.contains(&Value::object(
vec![
("name", Value::scalar("TWO")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
].into_iter()
.collect(),
))
);
assert!(values.contains(&Value::object(
vec![
("name", Value::scalar("TWO")),
("description", Value::null()),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
]
.into_iter()
.collect(),
)));
}
#[test]
@ -292,41 +291,42 @@ fn interface_introspection() {
assert_eq!(fields.len(), 1);
assert!(
fields.contains(&Value::object(
vec![
("name", Value::scalar("sampleEnum")),
(
"description",
Value::scalar("A sample field in the interface"),
),
("args", Value::list(vec![])),
(
"type",
Value::object(
vec![
("name", Value::null()),
("kind", Value::scalar("NON_NULL")),
(
"ofType",
Value::object(
vec![
("name", Value::scalar("SampleEnum")),
("kind", Value::scalar("ENUM")),
].into_iter()
.collect(),
),
assert!(fields.contains(&Value::object(
vec![
("name", Value::scalar("sampleEnum")),
(
"description",
Value::scalar("A sample field in the interface"),
),
("args", Value::list(vec![])),
(
"type",
Value::object(
vec![
("name", Value::null()),
("kind", Value::scalar("NON_NULL")),
(
"ofType",
Value::object(
vec![
("name", Value::scalar("SampleEnum")),
("kind", Value::scalar("ENUM")),
]
.into_iter()
.collect(),
),
].into_iter()
.collect(),
),
),
]
.into_iter()
.collect(),
),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
].into_iter()
.collect(),
))
);
),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
]
.into_iter()
.collect(),
)));
}
#[test]
@ -436,126 +436,133 @@ fn object_introspection() {
println!("Fields: {:#?}", fields);
assert!(
fields.contains(&Value::object(
vec![
("name", Value::scalar("sampleEnum")),
("description", Value::null()),
("args", Value::list(vec![])),
(
"type",
Value::object(
vec![
("name", Value::null()),
("kind", Value::scalar("NON_NULL")),
(
"ofType",
Value::object(
vec![
("name", Value::scalar("SampleEnum")),
("kind", Value::scalar("ENUM")),
].into_iter()
.collect(),
),
assert!(fields.contains(&Value::object(
vec![
("name", Value::scalar("sampleEnum")),
("description", Value::null()),
("args", Value::list(vec![])),
(
"type",
Value::object(
vec![
("name", Value::null()),
("kind", Value::scalar("NON_NULL")),
(
"ofType",
Value::object(
vec![
("name", Value::scalar("SampleEnum")),
("kind", Value::scalar("ENUM")),
]
.into_iter()
.collect(),
),
].into_iter()
.collect(),
),
),
]
.into_iter()
.collect(),
),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
].into_iter()
.collect(),
))
);
),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
]
.into_iter()
.collect(),
)));
assert!(
fields.contains(&Value::object(
vec![
("name", Value::scalar("sampleScalar")),
(
"description",
Value::scalar("A sample scalar field on the object"),
),
(
"args",
Value::list(vec![
Value::object(
vec![
("name", Value::scalar("first")),
("description", Value::scalar("The first number")),
(
"type",
Value::object(
vec![
("name", Value::null()),
("kind", Value::scalar("NON_NULL")),
(
"ofType",
Value::object(
vec![
("name", Value::scalar("Int")),
("kind", Value::scalar("SCALAR")),
("ofType", Value::null()),
].into_iter()
.collect(),
),
),
].into_iter()
.collect(),
),
),
("defaultValue", Value::null()),
].into_iter()
.collect(),
),
Value::object(
vec![
("name", Value::scalar("second")),
("description", Value::scalar("The second number")),
(
"type",
Value::object(
vec![
("name", Value::scalar("Int")),
("kind", Value::scalar("SCALAR")),
("ofType", Value::null()),
].into_iter()
.collect(),
),
),
("defaultValue", Value::scalar("123")),
].into_iter()
.collect(),
),
]),
),
(
"type",
assert!(fields.contains(&Value::object(
vec![
("name", Value::scalar("sampleScalar")),
(
"description",
Value::scalar("A sample scalar field on the object"),
),
(
"args",
Value::list(vec![
Value::object(
vec![
("name", Value::null()),
("kind", Value::scalar("NON_NULL")),
("name", Value::scalar("first")),
("description", Value::scalar("The first number")),
(
"ofType",
"type",
Value::object(
vec![
("name", Value::scalar("SampleScalar")),
("kind", Value::scalar("SCALAR")),
].into_iter()
("name", Value::null()),
("kind", Value::scalar("NON_NULL")),
(
"ofType",
Value::object(
vec![
("name", Value::scalar("Int")),
("kind", Value::scalar("SCALAR")),
("ofType", Value::null()),
]
.into_iter()
.collect(),
),
),
]
.into_iter()
.collect(),
),
),
].into_iter()
("defaultValue", Value::null()),
]
.into_iter()
.collect(),
),
Value::object(
vec![
("name", Value::scalar("second")),
("description", Value::scalar("The second number")),
(
"type",
Value::object(
vec![
("name", Value::scalar("Int")),
("kind", Value::scalar("SCALAR")),
("ofType", Value::null()),
]
.into_iter()
.collect(),
),
),
("defaultValue", Value::scalar("123")),
]
.into_iter()
.collect(),
),
]),
),
(
"type",
Value::object(
vec![
("name", Value::null()),
("kind", Value::scalar("NON_NULL")),
(
"ofType",
Value::object(
vec![
("name", Value::scalar("SampleScalar")),
("kind", Value::scalar("SCALAR")),
]
.into_iter()
.collect(),
),
),
]
.into_iter()
.collect(),
),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
].into_iter()
.collect(),
))
);
),
("isDeprecated", Value::scalar(false)),
("deprecationReason", Value::null()),
]
.into_iter()
.collect(),
)));
}
#[test]
@ -603,7 +610,8 @@ fn scalar_introspection() {
("enumValues", Value::null()),
("inputFields", Value::null()),
("ofType", Value::null()),
].into_iter()
]
.into_iter()
.collect()
)
);

View file

@ -185,10 +185,12 @@ fn variable_complex_input() {
("a", InputValue::scalar("foo")),
("b", InputValue::list(vec![InputValue::scalar("bar")])),
("c", InputValue::scalar("baz")),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect(),
|result: &Object<DefaultScalarValue>| {
assert_eq!(
@ -209,10 +211,12 @@ fn variable_parse_single_value_to_list() {
("a", InputValue::scalar("foo")),
("b", InputValue::scalar("bar")),
("c", InputValue::scalar("baz")),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect(),
|result: &Object<DefaultScalarValue>| {
assert_eq!(
@ -232,10 +236,12 @@ fn variable_runs_from_input_value_on_scalar() {
vec![
("c", InputValue::scalar("baz")),
("d", InputValue::scalar("SerializedValue")),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect(),
|result: &Object<DefaultScalarValue>| {
assert_eq!(
@ -257,10 +263,12 @@ fn variable_error_on_nested_non_null() {
("a", InputValue::scalar("foo")),
("b", InputValue::scalar("bar")),
("c", InputValue::null()),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect();
let error = ::execute(query, None, &schema, &vars, &()).unwrap_err();
@ -304,10 +312,12 @@ fn variable_error_on_omit_non_null() {
vec![
("a", InputValue::scalar("foo")),
("b", InputValue::scalar("bar")),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect();
let error = ::execute(query, None, &schema, &vars, &()).unwrap_err();
@ -333,10 +343,12 @@ fn variable_multiple_errors_with_nesting() {
vec![(
"na",
InputValue::object(vec![("a", InputValue::scalar("foo"))].into_iter().collect()),
)].into_iter()
)]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect();
let error = ::execute(query, None, &schema, &vars, &()).unwrap_err();
@ -366,10 +378,12 @@ fn variable_error_on_additional_field() {
("b", InputValue::scalar("bar")),
("c", InputValue::scalar("baz")),
("extra", InputValue::scalar("dog")),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect();
let error = ::execute(query, None, &schema, &vars, &()).unwrap_err();
@ -557,7 +571,8 @@ fn allow_lists_to_contain_values() {
vec![(
"input".to_owned(),
InputValue::list(vec![InputValue::scalar("A")]),
)].into_iter()
)]
.into_iter()
.collect(),
|result| {
assert_eq!(
@ -579,7 +594,8 @@ fn allow_lists_to_contain_null() {
InputValue::null(),
InputValue::scalar("B"),
]),
)].into_iter()
)]
.into_iter()
.collect(),
|result| {
assert_eq!(
@ -617,7 +633,8 @@ fn allow_non_null_lists_to_contain_values() {
vec![(
"input".to_owned(),
InputValue::list(vec![InputValue::scalar("A")]),
)].into_iter()
)]
.into_iter()
.collect(),
|result| {
assert_eq!(
@ -638,7 +655,8 @@ fn allow_non_null_lists_to_contain_null() {
InputValue::null(),
InputValue::scalar("B"),
]),
)].into_iter()
)]
.into_iter()
.collect(),
|result| {
assert_eq!(
@ -672,7 +690,8 @@ fn allow_lists_of_non_null_to_contain_values() {
vec![(
"input".to_owned(),
InputValue::list(vec![InputValue::scalar("A")]),
)].into_iter()
)]
.into_iter()
.collect(),
|result| {
assert_eq!(
@ -695,7 +714,8 @@ fn does_not_allow_lists_of_non_null_to_contain_null() {
InputValue::null(),
InputValue::scalar("B"),
]),
)].into_iter()
)]
.into_iter()
.collect();
let error = ::execute(query, None, &schema, &vars, &()).unwrap_err();
@ -720,7 +740,8 @@ fn does_not_allow_non_null_lists_of_non_null_to_contain_null() {
InputValue::null(),
InputValue::scalar("B"),
]),
)].into_iter()
)]
.into_iter()
.collect();
let error = ::execute(query, None, &schema, &vars, &()).unwrap_err();
@ -760,7 +781,8 @@ fn allow_non_null_lists_of_non_null_to_contain_values() {
vec![(
"input".to_owned(),
InputValue::list(vec![InputValue::scalar("A")]),
)].into_iter()
)]
.into_iter()
.collect(),
|result| {
assert_eq!(
@ -779,7 +801,8 @@ fn does_not_allow_invalid_types_to_be_used_as_values() {
let vars = vec![(
"value".to_owned(),
InputValue::list(vec![InputValue::scalar("A"), InputValue::scalar("B")]),
)].into_iter()
)]
.into_iter()
.collect();
let error = ::execute(query, None, &schema, &vars, &()).unwrap_err();
@ -800,7 +823,8 @@ fn does_not_allow_unknown_types_to_be_used_as_values() {
let vars = vec![(
"value".to_owned(),
InputValue::list(vec![InputValue::scalar("A"), InputValue::scalar("B")]),
)].into_iter()
)]
.into_iter()
.collect();
let error = ::execute(query, None, &schema, &vars, &()).unwrap_err();

View file

@ -33,7 +33,7 @@ impl<S> GraphQLRequest<S>
where
S: ScalarValue,
{
/// Returns the `operation_name` associated with this request.
/// Returns the `operation_name` associated with this request.
fn operation_name(&self) -> Option<&str> {
self.operation_name.as_ref().map(|oper_name| &**oper_name)
}
@ -47,7 +47,8 @@ where
.map(|(k, v)| (k.to_owned(), v.clone()))
.collect()
})
}).unwrap_or_default()
})
.unwrap_or_default()
}
/// Construct a new GraphQL request from parts
@ -207,7 +208,8 @@ pub mod tests {
.body
.as_ref()
.expect("No data returned from request"),
).expect("Could not parse JSON object")
)
.expect("Could not parse JSON object")
}
fn test_simple_get<T: HTTPIntegration>(integration: &T) {
@ -249,7 +251,8 @@ pub mod tests {
}
}
}"#
).expect("Invalid JSON constant in test")
)
.expect("Invalid JSON constant in test")
);
}
@ -279,7 +282,8 @@ pub mod tests {
}
}
}"#
).expect("Invalid JSON constant in test")
)
.expect("Invalid JSON constant in test")
);
}
@ -309,7 +313,8 @@ pub mod tests {
unwrap_json_response(&response),
serde_json::from_str::<Json>(
r#"[{"data": {"hero": {"name": "R2-D2"}}}, {"data": {"hero": {"name": "R2-D2"}}}]"#
).expect("Invalid JSON constant in test")
)
.expect("Invalid JSON constant in test")
);
}
@ -332,9 +337,12 @@ pub mod tests {
// {hero{name}}
let response = integration.get("/?query=%7B%22query%22%3A%20%22%7Bhero%7Bname%7D%7D%22%2C%20%22query%22%3A%20%22%7Bhero%7Bname%7D%7D%22%7D");
assert_eq!(response.status_code, 400);
let response = integration.post("/", r#"
let response = integration.post(
"/",
r#"
{"query": "{hero{name}}", "query": "{hero{name}}"}
"#);
"#,
);
assert_eq!(response.status_code, 400);
}
}

View file

@ -203,7 +203,7 @@ mod integration_test {
use executor::Variables;
use schema::model::RootNode;
use types::scalars::EmptyMutation;
use value::{Value};
use value::Value;
#[test]
fn test_serialization() {
@ -232,7 +232,7 @@ mod integration_test {
}
"#;
let schema= RootNode::new(Root, EmptyMutation::<()>::new());
let schema = RootNode::new(Root, EmptyMutation::<()>::new());
let (result, errs) =
::execute(doc, None, &schema, &Variables::new(), &()).expect("Execution failed");
@ -253,7 +253,8 @@ mod integration_test {
"exampleDateTimeUtc",
Value::scalar("1970-01-01T00:01:01+00:00"),
),
].into_iter()
]
.into_iter()
.collect()
)
);

View file

@ -55,16 +55,16 @@ impl<'a> ser::Serialize for GraphQLError<'a> {
GraphQLError::NoOperationProvided => [SerializeHelper {
message: "Must provide an operation",
}]
.serialize(serializer),
.serialize(serializer),
GraphQLError::MultipleOperationsProvided => [SerializeHelper {
message: "Must provide operation name \
if query contains multiple operations",
}]
.serialize(serializer),
.serialize(serializer),
GraphQLError::UnknownOperationName => [SerializeHelper {
message: "Unknown operation",
}]
.serialize(serializer),
.serialize(serializer),
}
}
}
@ -167,7 +167,7 @@ where
self.0.visit_u64(value).map(InputValue::Scalar)
}
serde_if_integer128!{
serde_if_integer128! {
fn visit_u128<E>(self, value: u128) -> Result<InputValue<S>, E>
where
E: de::Error,

View file

@ -37,7 +37,9 @@ macro_rules! __juniper_impl_trait {
#[doc(hidden)]
#[macro_export]
macro_rules! __juniper_insert_generic {
(<DefaultScalarValue>) => {$crate::DefaultScalarValue};
(<DefaultScalarValue>) => {
$crate::DefaultScalarValue
};
(
<$generic:tt $(: $bound: tt)*>
) => {
@ -50,7 +52,6 @@ macro_rules! __juniper_insert_generic {
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __juniper_parse_object_header {
@ -560,7 +561,6 @@ macro_rules! __juniper_parse_field_list {
}
#[doc(hidden)]
#[macro_export]
macro_rules! __juniper_parse_instance_resolver {

File diff suppressed because it is too large Load diff

View file

@ -154,7 +154,8 @@ where
.as_scalar_value::<String>()
.expect("name is not a string")
== field_name
}).next()
})
.next()
.expect("Field not found")
.as_object_value()
.expect("Field is not an object");
@ -425,7 +426,9 @@ fn introspect_object_field_attr_description_collapse() {
);
assert_eq!(
field.get_field_value("description"),
Some(&Value::scalar("Field description\nwith `collapse_docs` behavior"))
Some(&Value::scalar(
"Field description\nwith `collapse_docs` behavior"
))
);
assert_eq!(
field.get_field_value("isDeprecated"),
@ -447,7 +450,9 @@ fn introspect_interface_field_attr_description_collapse() {
);
assert_eq!(
field.get_field_value("description"),
Some(&Value::scalar("Field description\nwith `collapse_docs` behavior"))
Some(&Value::scalar(
"Field description\nwith `collapse_docs` behavior"
))
);
assert_eq!(
field.get_field_value("isDeprecated"),

View file

@ -3,7 +3,7 @@ use std::marker::PhantomData;
use ast::InputValue;
use schema::model::RootNode;
use types::scalars::EmptyMutation;
use value::{Value, Object, DefaultScalarValue};
use value::{DefaultScalarValue, Object, Value};
/*
@ -179,102 +179,105 @@ fn introspect_custom_name() {
);
assert_eq!(object.get_field_value("description"), Some(&Value::null()));
assert!(
fields.contains(&Value::object(
vec![("name", Value::scalar("simple"))]
.into_iter()
.collect(),
))
);
assert!(fields.contains(&Value::object(
vec![("name", Value::scalar("simple"))]
.into_iter()
.collect(),
)));
});
}
#[test]
fn introspect_with_lifetime() {
run_type_info_query("WithLifetime", |object, fields| {
assert_eq!(object.get_field_value("name"), Some(&Value::scalar("WithLifetime")));
assert_eq!(
object.get_field_value("name"),
Some(&Value::scalar("WithLifetime"))
);
assert_eq!(object.get_field_value("description"), Some(&Value::null()));
assert!(
fields.contains(&Value::object(
vec![("name", Value::scalar("simple"))]
.into_iter()
.collect(),
))
);
assert!(fields.contains(&Value::object(
vec![("name", Value::scalar("simple"))]
.into_iter()
.collect(),
)));
});
}
#[test]
fn introspect_with_generics() {
run_type_info_query("WithGenerics", |object, fields| {
assert_eq!(object.get_field_value("name"), Some(&Value::scalar("WithGenerics")));
assert_eq!(
object.get_field_value("name"),
Some(&Value::scalar("WithGenerics"))
);
assert_eq!(object.get_field_value("description"), Some(&Value::null()));
assert!(
fields.contains(&Value::object(
vec![("name", Value::scalar("simple"))]
.into_iter()
.collect(),
))
);
assert!(fields.contains(&Value::object(
vec![("name", Value::scalar("simple"))]
.into_iter()
.collect(),
)));
});
}
#[test]
fn introspect_description_first() {
run_type_info_query("DescriptionFirst", |object, fields| {
assert_eq!(object.get_field_value("name"), Some(&Value::scalar("DescriptionFirst")));
assert_eq!(
object.get_field_value("name"),
Some(&Value::scalar("DescriptionFirst"))
);
assert_eq!(
object.get_field_value("description"),
Some(&Value::scalar("A description"))
);
assert!(
fields.contains(&Value::object(
vec![("name", Value::scalar("simple"))]
.into_iter()
.collect(),
))
);
assert!(fields.contains(&Value::object(
vec![("name", Value::scalar("simple"))]
.into_iter()
.collect(),
)));
});
}
#[test]
fn introspect_fields_first() {
run_type_info_query("FieldsFirst", |object, fields| {
assert_eq!(object.get_field_value("name"), Some(&Value::scalar("FieldsFirst")));
assert_eq!(
object.get_field_value("name"),
Some(&Value::scalar("FieldsFirst"))
);
assert_eq!(
object.get_field_value("description"),
Some(&Value::scalar("A description"))
);
assert!(
fields.contains(&Value::object(
vec![("name", Value::scalar("simple"))]
.into_iter()
.collect(),
))
);
assert!(fields.contains(&Value::object(
vec![("name", Value::scalar("simple"))]
.into_iter()
.collect(),
)));
});
}
#[test]
fn introspect_interfaces_first() {
run_type_info_query("InterfacesFirst", |object, fields| {
assert_eq!(object.get_field_value("name"), Some(&Value::scalar("InterfacesFirst")));
assert_eq!(
object.get_field_value("name"),
Some(&Value::scalar("InterfacesFirst"))
);
assert_eq!(
object.get_field_value("description"),
Some(&Value::scalar("A description"))
);
assert!(
fields.contains(&Value::object(
vec![("name", Value::scalar("simple"))]
.into_iter()
.collect(),
))
);
assert!(fields.contains(&Value::object(
vec![("name", Value::scalar("simple"))]
.into_iter()
.collect(),
)));
});
}
@ -290,32 +293,31 @@ fn introspect_commas_with_trailing() {
Some(&Value::scalar("A description"))
);
assert!(
fields.contains(&Value::object(
vec![("name", Value::scalar("simple"))]
.into_iter()
.collect(),
))
);
assert!(fields.contains(&Value::object(
vec![("name", Value::scalar("simple"))]
.into_iter()
.collect(),
)));
});
}
#[test]
fn introspect_commas_on_meta() {
run_type_info_query("CommasOnMeta", |object, fields| {
assert_eq!(object.get_field_value("name"), Some(&Value::scalar("CommasOnMeta")));
assert_eq!(
object.get_field_value("name"),
Some(&Value::scalar("CommasOnMeta"))
);
assert_eq!(
object.get_field_value("description"),
Some(&Value::scalar("A description"))
);
assert!(
fields.contains(&Value::object(
vec![("name", Value::scalar("simple"))]
.into_iter()
.collect(),
))
);
assert!(fields.contains(&Value::object(
vec![("name", Value::scalar("simple"))]
.into_iter()
.collect(),
)));
});
}
@ -331,12 +333,10 @@ fn introspect_resolvers_with_trailing_comma() {
Some(&Value::scalar("A description"))
);
assert!(
fields.contains(&Value::object(
vec![("name", Value::scalar("simple"))]
.into_iter()
.collect(),
))
);
assert!(fields.contains(&Value::object(
vec![("name", Value::scalar("simple"))]
.into_iter()
.collect(),
)));
});
}

View file

@ -274,7 +274,8 @@ fn introspect_description_first() {
vec![
("name", Value::scalar("Interface")),
("kind", Value::scalar("INTERFACE")),
].into_iter()
]
.into_iter()
.collect(),
)]))
);
@ -303,7 +304,8 @@ fn introspect_fields_first() {
vec![
("name", Value::scalar("Interface")),
("kind", Value::scalar("INTERFACE")),
].into_iter()
]
.into_iter()
.collect(),
)]))
);
@ -332,7 +334,8 @@ fn introspect_interfaces_first() {
vec![
("name", Value::scalar("Interface")),
("kind", Value::scalar("INTERFACE")),
].into_iter()
]
.into_iter()
.collect(),
)]))
);
@ -361,7 +364,8 @@ fn introspect_commas_with_trailing() {
vec![
("name", Value::scalar("Interface")),
("kind", Value::scalar("INTERFACE")),
].into_iter()
]
.into_iter()
.collect(),
)]))
);
@ -390,7 +394,8 @@ fn introspect_commas_on_meta() {
vec![
("name", Value::scalar("Interface")),
("kind", Value::scalar("INTERFACE")),
].into_iter()
]
.into_iter()
.collect(),
)]))
);

View file

@ -1,7 +1,7 @@
use executor::Variables;
use schema::model::RootNode;
use types::scalars::EmptyMutation;
use value::{Value, Object, DefaultScalarValue, ParseScalarValue, ParseScalarResult};
use value::{DefaultScalarValue, Object, ParseScalarResult, ParseScalarValue, Value};
struct DefaultName(i32);
struct OtherOrder(i32);
@ -140,8 +140,14 @@ fn default_name_introspection() {
"#;
run_type_info_query(doc, |type_info| {
assert_eq!(type_info.get_field_value("name"), Some(&Value::scalar("DefaultName")));
assert_eq!(type_info.get_field_value("description"), Some(&Value::null()));
assert_eq!(
type_info.get_field_value("name"),
Some(&Value::scalar("DefaultName"))
);
assert_eq!(
type_info.get_field_value("description"),
Some(&Value::null())
);
});
}
@ -157,8 +163,14 @@ fn other_order_introspection() {
"#;
run_type_info_query(doc, |type_info| {
assert_eq!(type_info.get_field_value("name"), Some(&Value::scalar("OtherOrder")));
assert_eq!(type_info.get_field_value("description"), Some(&Value::null()));
assert_eq!(
type_info.get_field_value("name"),
Some(&Value::scalar("OtherOrder"))
);
assert_eq!(
type_info.get_field_value("description"),
Some(&Value::null())
);
});
}
@ -174,8 +186,14 @@ fn named_introspection() {
"#;
run_type_info_query(doc, |type_info| {
assert_eq!(type_info.get_field_value("name"), Some(&Value::scalar("ANamedScalar")));
assert_eq!(type_info.get_field_value("description"), Some(&Value::null()));
assert_eq!(
type_info.get_field_value("name"),
Some(&Value::scalar("ANamedScalar"))
);
assert_eq!(
type_info.get_field_value("description"),
Some(&Value::null())
);
});
}

View file

@ -3,7 +3,7 @@ use std::marker::PhantomData;
use ast::InputValue;
use schema::model::RootNode;
use types::scalars::EmptyMutation;
use value::{Value, Object, DefaultScalarValue};
use value::{DefaultScalarValue, Object, Value};
/*
@ -154,86 +154,91 @@ where
#[test]
fn introspect_custom_name() {
run_type_info_query("ACustomNamedUnion", |union, possible_types| {
assert_eq!(union.get_field_value("name"), Some(&Value::scalar("ACustomNamedUnion")));
assert_eq!(
union.get_field_value("name"),
Some(&Value::scalar("ACustomNamedUnion"))
);
assert_eq!(union.get_field_value("description"), Some(&Value::null()));
assert!(
possible_types.contains(&Value::object(
vec![("name", Value::scalar("Concrete"))]
.into_iter()
.collect(),
))
);
assert!(possible_types.contains(&Value::object(
vec![("name", Value::scalar("Concrete"))]
.into_iter()
.collect(),
)));
});
}
#[test]
fn introspect_with_lifetime() {
run_type_info_query("WithLifetime", |union, possible_types| {
assert_eq!(union.get_field_value("name"), Some(&Value::scalar("WithLifetime")));
assert_eq!(
union.get_field_value("name"),
Some(&Value::scalar("WithLifetime"))
);
assert_eq!(union.get_field_value("description"), Some(&Value::null()));
assert!(
possible_types.contains(&Value::object(
vec![("name", Value::scalar("Concrete"))]
.into_iter()
.collect(),
))
);
assert!(possible_types.contains(&Value::object(
vec![("name", Value::scalar("Concrete"))]
.into_iter()
.collect(),
)));
});
}
#[test]
fn introspect_with_generics() {
run_type_info_query("WithGenerics", |union, possible_types| {
assert_eq!(union.get_field_value("name"), Some(&Value::scalar("WithGenerics")));
assert_eq!(
union.get_field_value("name"),
Some(&Value::scalar("WithGenerics"))
);
assert_eq!(union.get_field_value("description"), Some(&Value::null()));
assert!(
possible_types.contains(&Value::object(
vec![("name", Value::scalar("Concrete"))]
.into_iter()
.collect(),
))
);
assert!(possible_types.contains(&Value::object(
vec![("name", Value::scalar("Concrete"))]
.into_iter()
.collect(),
)));
});
}
#[test]
fn introspect_description_first() {
run_type_info_query("DescriptionFirst", |union, possible_types| {
assert_eq!(union.get_field_value("name"), Some(&Value::scalar("DescriptionFirst")));
assert_eq!(
union.get_field_value("name"),
Some(&Value::scalar("DescriptionFirst"))
);
assert_eq!(
union.get_field_value("description"),
Some(&Value::scalar("A description"))
);
assert!(
possible_types.contains(&Value::object(
vec![("name", Value::scalar("Concrete"))]
.into_iter()
.collect(),
))
);
assert!(possible_types.contains(&Value::object(
vec![("name", Value::scalar("Concrete"))]
.into_iter()
.collect(),
)));
});
}
#[test]
fn introspect_resolvers_first() {
run_type_info_query("ResolversFirst", |union, possible_types| {
assert_eq!(union.get_field_value("name"), Some(&Value::scalar("ResolversFirst")));
assert_eq!(
union.get_field_value("name"),
Some(&Value::scalar("ResolversFirst"))
);
assert_eq!(
union.get_field_value("description"),
Some(&Value::scalar("A description"))
);
assert!(
possible_types.contains(&Value::object(
vec![("name", Value::scalar("Concrete"))]
.into_iter()
.collect(),
))
);
assert!(possible_types.contains(&Value::object(
vec![("name", Value::scalar("Concrete"))]
.into_iter()
.collect(),
)));
});
}
@ -249,13 +254,11 @@ fn introspect_commas_with_trailing() {
Some(&Value::scalar("A description"))
);
assert!(
possible_types.contains(&Value::object(
vec![("name", Value::scalar("Concrete"))]
.into_iter()
.collect(),
))
);
assert!(possible_types.contains(&Value::object(
vec![("name", Value::scalar("Concrete"))]
.into_iter()
.collect(),
)));
});
}
@ -271,12 +274,10 @@ fn introspect_resolvers_with_trailing_comma() {
Some(&Value::scalar("A description"))
);
assert!(
possible_types.contains(&Value::object(
vec![("name", Value::scalar("Concrete"))]
.into_iter()
.collect(),
))
);
assert!(possible_types.contains(&Value::object(
vec![("name", Value::scalar("Concrete"))]
.into_iter()
.collect(),
)));
});
}

View file

@ -129,11 +129,13 @@ where
start: start_pos, ..
} = parser.expect(&Token::Name("fragment"))?;
let name = match parser.expect_name() {
Ok(n) => if n.item == "on" {
return Err(n.map(|_| ParseError::UnexpectedToken(Token::Name("on"))));
} else {
n
},
Ok(n) => {
if n.item == "on" {
return Err(n.map(|_| ParseError::UnexpectedToken(Token::Name("on"))));
} else {
n
}
}
Err(e) => return Err(e),
};
@ -354,7 +356,8 @@ where
&Token::ParenOpen,
|p| parse_argument(p, schema, arguments),
&Token::ParenClose,
)?.map(|args| Arguments {
)?
.map(|args| Arguments {
items: args.into_iter().map(|s| s.item).collect(),
}),
))
@ -408,7 +411,8 @@ where
&Token::ParenOpen,
|p| parse_variable_definition(p, schema),
&Token::ParenClose,
)?.map(|defs| VariableDefinitions {
)?
.map(|defs| VariableDefinitions {
items: defs.into_iter().map(|s| s.item).collect(),
}),
))

View file

@ -24,7 +24,7 @@ pub struct Lexer<'a> {
pub enum ScalarToken<'a> {
String(&'a str),
Float(&'a str),
Int(&'a str)
Int(&'a str),
}
/// A single token in the input source
@ -231,32 +231,32 @@ impl<'a> Lexer<'a> {
let mut old_pos = self.position;
while let Some((idx, ch)) = self.next_char() {
match ch {
'b' |'f' |'n'|'r' |'t'|'\\'|'/'| '"' if escaped => {
'b' | 'f' | 'n' | 'r' | 't' | '\\' | '/' | '"' if escaped => {
escaped = false;
}
'u' if escaped => {
self.scan_escaped_unicode(&old_pos)?;
escaped = false;
},
}
c if escaped => {
return Err(Spanning::zero_width(
&old_pos,
LexerError::UnknownEscapeSequence(format!("\\{}", c))
))
LexerError::UnknownEscapeSequence(format!("\\{}", c)),
))
}
'\\' => escaped = true,
'"' if !escaped => {
return Ok(Spanning::start_end(
&start_pos,
&self.position,
Token::Scalar(ScalarToken::String(&self.source[start_idx+1..idx])),
Token::Scalar(ScalarToken::String(&self.source[start_idx + 1..idx])),
));
}
'\n' | '\r' => {
return Err(Spanning::zero_width(
&old_pos,
LexerError::UnterminatedString,
));
));
}
c if !is_source_char(c) => {
return Err(Spanning::zero_width(
@ -316,12 +316,14 @@ impl<'a> Lexer<'a> {
)
})?;
char::from_u32(code_point).ok_or_else(|| {
Spanning::zero_width(
start_pos,
LexerError::UnknownEscapeSequence("\\u".to_owned() + escape),
)
}).map(|_|())
char::from_u32(code_point)
.ok_or_else(|| {
Spanning::zero_width(
start_pos,
LexerError::UnknownEscapeSequence("\\u".to_owned() + escape),
)
})
.map(|_| ())
}
fn scan_number(&mut self) -> LexerResult<'a> {
@ -424,15 +426,11 @@ impl<'a> Lexer<'a> {
let token = if is_float {
Token::Scalar(ScalarToken::Float(number))
}else {
} else {
Token::Scalar(ScalarToken::Int(number))
};
Ok(Spanning::start_end(
&start_pos,
end_pos,
token,
))
Ok(Spanning::start_end(&start_pos, end_pos, token))
}
}
@ -463,16 +461,18 @@ impl<'a> Iterator for Lexer<'a> {
Some('|') => Ok(self.emit_single_char(Token::Pipe)),
Some('.') => self.scan_ellipsis(),
Some('"') => self.scan_string(),
Some(ch) => if is_number_start(ch) {
self.scan_number()
} else if is_name_start(ch) {
self.scan_name()
} else {
Err(Spanning::zero_width(
&self.position,
LexerError::UnknownCharacter(ch),
))
},
Some(ch) => {
if is_number_start(ch) {
self.scan_number()
} else if is_name_start(ch) {
self.scan_name()
} else {
Err(Spanning::zero_width(
&self.position,
LexerError::UnknownCharacter(ch),
))
}
}
None => {
self.has_reached_eof = true;
Ok(Spanning::zero_width(&self.position, Token::EndOfFile))
@ -485,10 +485,12 @@ impl<'a> fmt::Display for Token<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Token::Name(name) => write!(f, "{}", name),
Token::Scalar(ScalarToken::Int(s)) | Token::Scalar(ScalarToken::Float(s)) => write!(f, "{}", s),
Token::Scalar(ScalarToken::Int(s)) | Token::Scalar(ScalarToken::Float(s)) => {
write!(f, "{}", s)
}
Token::Scalar(ScalarToken::String(s)) => {
write!(f, "\"{}\"", s.replace('\\', "\\\\").replace('"', "\\\""))
},
}
Token::ExclamationMark => write!(f, "!"),
Token::Dollar => write!(f, "$"),
Token::ParenOpen => write!(f, "("),

View file

@ -11,6 +11,6 @@ mod tests;
pub use self::document::parse_document_source;
pub use self::lexer::{Lexer, LexerError, Token, ScalarToken};
pub use self::lexer::{Lexer, LexerError, ScalarToken, Token};
pub use self::parser::{OptionParseResult, ParseError, ParseResult, Parser, UnlocatedParseResult};
pub use self::utils::{SourcePosition, Spanning};

View file

@ -5,7 +5,7 @@ use parser::document::parse_document_source;
use parser::{ParseError, SourcePosition, Spanning, Token};
use schema::model::SchemaType;
use validation::test_harness::{MutationRoot, QueryRoot};
use value::{ScalarRefValue, ScalarValue, DefaultScalarValue};
use value::{DefaultScalarValue, ScalarRefValue, ScalarValue};
fn parse_document<S>(s: &str) -> Document<S>
where

View file

@ -1,4 +1,4 @@
use parser::{Lexer, LexerError, SourcePosition, Spanning, Token, ScalarToken};
use parser::{Lexer, LexerError, ScalarToken, SourcePosition, Spanning, Token};
fn tokenize_to_vec<'a>(s: &'a str) -> Vec<Spanning<Token<'a>>> {
let mut tokens = Vec::new();
@ -35,9 +35,11 @@ fn tokenize_error(s: &str) -> Spanning<LexerError> {
loop {
match lexer.next() {
Some(Ok(t)) => if t.item == Token::EndOfFile {
panic!("Tokenizer did not return error for {:#?}", s);
},
Some(Ok(t)) => {
if t.item == Token::EndOfFile {
panic!("Tokenizer did not return error for {:#?}", s);
}
}
Some(Err(e)) => {
return e;
}
@ -133,7 +135,8 @@ fn error_positions() {
?
"#
).next(),
)
.next(),
Some(Err(Spanning::zero_width(
&SourcePosition::new(14, 2, 12),
LexerError::UnknownCharacter('?')
@ -654,7 +657,10 @@ fn display() {
assert_eq!(format!("{}", Token::Scalar(ScalarToken::Int("123"))), "123");
assert_eq!(format!("{}", Token::Scalar(ScalarToken::Float("4.5"))), "4.5");
assert_eq!(
format!("{}", Token::Scalar(ScalarToken::Float("4.5"))),
"4.5"
);
assert_eq!(
format!("{}", Token::Scalar(ScalarToken::String("some string"))),

View file

@ -5,13 +5,13 @@ use parser::value::parse_value_literal;
use parser::{Lexer, Parser, SourcePosition, Spanning};
use value::{DefaultScalarValue, ParseScalarValue, ScalarRefValue, ScalarValue};
use schema::meta::{MetaType, ScalarMeta, EnumMeta, EnumValue, InputObjectMeta, Argument};
use schema::meta::{Argument, EnumMeta, EnumValue, InputObjectMeta, MetaType, ScalarMeta};
use schema::model::SchemaType;
use types::scalars::EmptyMutation;
#[derive(GraphQLEnumInternal)]
enum Enum {
EnumValue
EnumValue,
}
#[derive(GraphQLInputObjectInternal)]
@ -168,8 +168,10 @@ fn input_value_literals() {
])
)
);
let fields = [ Argument::new("key", Type::NonNullNamed("Int".into())),
Argument::new("other", Type::NonNullNamed("Bar".into()))];
let fields = [
Argument::new("key", Type::NonNullNamed("Int".into())),
Argument::new("other", Type::NonNullNamed("Bar".into())),
];
let meta = &MetaType::InputObject(InputObjectMeta::new::<Foo>("foo".into(), &fields));
assert_eq!(
parse_value::<DefaultScalarValue>("{}", meta),
@ -181,10 +183,7 @@ fn input_value_literals() {
);
assert_eq!(
parse_value::<DefaultScalarValue>(
r#"{key: 123, other: {foo: "bar"}}"#,
meta
),
parse_value::<DefaultScalarValue>(r#"{key: 123, other: {foo: "bar"}}"#, meta),
Spanning::start_end(
&SourcePosition::new(0, 0, 0),
&SourcePosition::new(31, 0, 31),

View file

@ -42,11 +42,7 @@ where
..
},
_,
)
if !is_const =>
{
parse_variable_literal(parser)
}
) if !is_const => parse_variable_literal(parser),
(
&Spanning {
item: Token::Scalar(_),
@ -133,7 +129,8 @@ where
&Token::BracketOpen,
|p| parse_value_literal(p, is_const, schema, tpe),
&Token::BracketClose,
)?.map(InputValue::parsed_list))
)?
.map(InputValue::parsed_list))
}
fn parse_object_literal<'a, 'b, S>(
@ -150,7 +147,8 @@ where
&Token::CurlyOpen,
|p| parse_object_field(p, is_const, schema, object_tpe),
&Token::CurlyClose,
)?.map(|items| InputValue::parsed_object(items.into_iter().map(|s| s.item).collect())))
)?
.map(|items| InputValue::parsed_object(items.into_iter().map(|s| s.item).collect())))
}
fn parse_object_field<'a, 'b, S>(

View file

@ -365,8 +365,9 @@ impl<'a, S> MetaType<'a, S> {
}
pub(crate) fn fields<'b>(&self, schema: &'b SchemaType<S>) -> Option<Vec<&'b Field<'b, S>>> {
schema.lookup_type(&self.as_type()).and_then(|tpe| {
match *tpe {
schema
.lookup_type(&self.as_type())
.and_then(|tpe| match *tpe {
MetaType::Interface(ref i) => Some(i.fields.iter().collect()),
MetaType::Object(ref o) => Some(o.fields.iter().collect()),
MetaType::Union(ref u) => Some(
@ -378,8 +379,7 @@ impl<'a, S> MetaType<'a, S> {
.collect(),
),
_ => None,
}
})
})
}
}
@ -687,9 +687,7 @@ impl<'a, S> Argument<'a, S> {
desc.push('\n');
desc.push_str(&docstring);
}
desc @ &mut None => {
*desc = Some(docstring)
}
desc @ &mut None => *desc = Some(docstring),
}
}
self
@ -800,6 +798,7 @@ fn clean_docstring(multiline: &[&str]) -> Option<String> {
.take_while(move |_| line < multiline.len() - 1)
.cloned(),
)
}).collect::<String>(),
})
.collect::<String>(),
)
}

View file

@ -302,7 +302,8 @@ impl<'a, S> SchemaType<'a, S> {
..
}) => interface_names.iter().any(|iname| iname == name),
_ => false,
}).collect(),
})
.collect(),
_ => panic!("Can't retrieve possible types from non-abstract meta type"),
}
}

View file

@ -31,10 +31,12 @@ fn test_query_type_name() {
Value::object(
vec![("name", Value::scalar("Query"))].into_iter().collect(),
),
)].into_iter()
)]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]
@ -60,7 +62,8 @@ fn test_specific_type_name() {
vec![(
"__type",
Value::object(vec![("name", Value::scalar("Droid"))].into_iter().collect()),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]
@ -91,10 +94,12 @@ fn test_specific_object_type_name_and_kind() {
vec![
("name", Value::scalar("Droid")),
("kind", Value::scalar("OBJECT")),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]
@ -125,10 +130,12 @@ fn test_specific_interface_type_name_and_kind() {
vec![
("name", Value::scalar("Character")),
("kind", Value::scalar("INTERFACE")),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]
@ -162,10 +169,12 @@ fn test_documentation() {
"description",
Value::scalar("A mechanical creature in the Star Wars universe."),
),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]
@ -214,7 +223,8 @@ fn test_possible_types() {
.expect("'name' not present in type")
.as_scalar_value::<String>()
.expect("'name' not a string") as &str
}).collect::<HashSet<_>>();
})
.collect::<HashSet<_>>();
assert_eq!(possible_types, vec!["Human", "Droid"].into_iter().collect());
}

View file

@ -23,7 +23,8 @@ fn test_hero_name() {
vec![(
"hero",
Value::object(vec![("name", Value::scalar("R2-D2"))].into_iter().collect()),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]
@ -53,10 +54,12 @@ fn test_hero_field_order() {
vec![
("id", Value::scalar("2001")),
("name", Value::scalar("R2-D2")),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]
@ -80,10 +83,12 @@ fn test_hero_field_order() {
vec![
("name", Value::scalar("R2-D2")),
("id", Value::scalar("2001")),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]
@ -136,10 +141,12 @@ fn test_hero_name_and_friends() {
),
]),
),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]
@ -202,7 +209,8 @@ fn test_hero_name_and_friends_and_friends_of_friends() {
vec![(
"name",
Value::scalar("Leia Organa"),
)].into_iter()
)]
.into_iter()
.collect(),
),
Value::object(
@ -217,7 +225,8 @@ fn test_hero_name_and_friends_and_friends_of_friends() {
),
]),
),
].into_iter()
]
.into_iter()
.collect(),
),
Value::object(
@ -238,14 +247,16 @@ fn test_hero_name_and_friends_and_friends_of_friends() {
vec![(
"name",
Value::scalar("Luke Skywalker"),
)].into_iter()
)]
.into_iter()
.collect(),
),
Value::object(
vec![(
"name",
Value::scalar("Leia Organa"),
)].into_iter()
)]
.into_iter()
.collect(),
),
Value::object(
@ -255,7 +266,8 @@ fn test_hero_name_and_friends_and_friends_of_friends() {
),
]),
),
].into_iter()
]
.into_iter()
.collect(),
),
Value::object(
@ -276,7 +288,8 @@ fn test_hero_name_and_friends_and_friends_of_friends() {
vec![(
"name",
Value::scalar("Luke Skywalker"),
)].into_iter()
)]
.into_iter()
.collect(),
),
Value::object(
@ -296,15 +309,18 @@ fn test_hero_name_and_friends_and_friends_of_friends() {
),
]),
),
].into_iter()
]
.into_iter()
.collect(),
),
]),
),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]
@ -329,7 +345,8 @@ fn test_query_name() {
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]
@ -354,7 +371,8 @@ fn test_query_alias_single() {
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]
@ -393,7 +411,8 @@ fn test_query_alias_multiple() {
.collect(),
),
),
].into_iter()
]
.into_iter()
.collect()
),
vec![]
@ -427,7 +446,8 @@ fn test_query_alias_multiple_with_fragment() {
vec![
("name", Value::scalar("Luke Skywalker")),
("homePlanet", Value::scalar("Tatooine")),
].into_iter()
]
.into_iter()
.collect(),
),
),
@ -437,11 +457,13 @@ fn test_query_alias_multiple_with_fragment() {
vec![
("name", Value::scalar("Leia Organa")),
("homePlanet", Value::scalar("Alderaan")),
].into_iter()
]
.into_iter()
.collect(),
),
),
].into_iter()
]
.into_iter()
.collect()
),
vec![]
@ -470,7 +492,8 @@ fn test_query_name_variable() {
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]
@ -530,10 +553,12 @@ fn test_query_friends_names() {
vec![("name", Value::scalar("R2-D2"))].into_iter().collect(),
),
]),
)].into_iter()
)]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]
@ -569,10 +594,12 @@ fn test_query_inline_fragments_droid() {
("name", Value::scalar("R2-D2")),
("__typename", Value::scalar("Droid")),
("primaryFunction", Value::scalar("Astromech")),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]
@ -603,10 +630,12 @@ fn test_query_inline_fragments_human() {
vec![
("name", Value::scalar("Luke Skywalker")),
("__typename", Value::scalar("Human")),
].into_iter()
]
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]
@ -636,7 +665,8 @@ fn test_object_typename() {
.into_iter()
.collect(),
),
)].into_iter()
)]
.into_iter()
.collect()
),
vec![]

View file

@ -82,7 +82,8 @@ fn test_node() {
("foo", Value::scalar("1")),
("bar", Value::scalar("2")),
("baz", Value::scalar("3")),
].into_iter()
]
.into_iter()
.collect()
),
vec![]

View file

@ -355,7 +355,8 @@ where
T::name(info)
.expect("Resolving named type's selection set")
.as_ref(),
).expect("Type not found in schema");
)
.expect("Type not found in schema");
for selection in selection_set {
match *selection {
@ -404,7 +405,8 @@ where
.iter()
.map(|&(ref k, ref v)| {
(k.item, v.item.clone().into_const(exec_vars))
}).collect()
})
.collect()
}),
&meta_field.arguments,
),

View file

@ -121,11 +121,13 @@ where
None
}
}
ref other => if let Some(e) = other.convert() {
Some(vec![e])
} else {
None
},
ref other => {
if let Some(e) = other.convert() {
Some(vec![e])
} else {
None
}
}
}
}
}

View file

@ -11,7 +11,7 @@ impl<S, T, CtxT> GraphQLType<S> for Box<T>
where
S: ScalarValue,
T: GraphQLType<S, Context = CtxT>,
for<'b> &'b S: ScalarRefValue<'b>
for<'b> &'b S: ScalarRefValue<'b>,
{
type Context = CtxT;
type TypeInfo = T::TypeInfo;
@ -65,7 +65,7 @@ where
{
fn from_input_value<'a>(v: &'a InputValue<S>) -> Option<Box<T>>
where
for<'b> &'b S: ScalarRefValue<'b>
for<'b> &'b S: ScalarRefValue<'b>,
{
match <T as FromInputValue<S>>::from_input_value(v) {
Some(v) => Some(Box::new(v)),
@ -88,7 +88,7 @@ impl<'a, S, T, CtxT> GraphQLType<S> for &'a T
where
S: ScalarValue,
T: GraphQLType<S, Context = CtxT>,
for<'b> &'b S: ScalarRefValue<'b>
for<'b> &'b S: ScalarRefValue<'b>,
{
type Context = CtxT;
type TypeInfo = T::TypeInfo;
@ -149,7 +149,7 @@ impl<S, T> GraphQLType<S> for Arc<T>
where
S: ScalarValue,
T: GraphQLType<S>,
for<'b> &'b S: ScalarRefValue<'b>
for<'b> &'b S: ScalarRefValue<'b>,
{
type Context = T::Context;
type TypeInfo = T::TypeInfo;

View file

@ -116,14 +116,16 @@ where
.next()
.ok_or_else(|| {
ParseError::LexerError(LexerError::UnknownEscapeSequence(String::from("\\u")))
}).and_then(|c1| {
})
.and_then(|c1| {
char_iter
.next()
.map(|c2| format!("{}{}", c1, c2))
.ok_or_else(|| {
ParseError::LexerError(LexerError::UnknownEscapeSequence(format!("\\u{}", c1)))
})
}).and_then(|mut s| {
})
.and_then(|mut s| {
char_iter
.next()
.ok_or_else(|| {
@ -131,11 +133,13 @@ where
"\\u{}",
s.clone()
)))
}).map(|c2| {
})
.map(|c2| {
s.push(c2);
s
})
}).and_then(|mut s| {
})
.and_then(|mut s| {
char_iter
.next()
.ok_or_else(|| {
@ -143,7 +147,8 @@ where
"\\u{}",
s.clone()
)))
}).map(|c2| {
})
.map(|c2| {
s.push(c2);
s
})

View file

@ -13,11 +13,13 @@ where
S: ScalarValue,
{
match *arg_type {
TypeType::NonNull(ref inner) => if arg_value.is_null() {
false
} else {
is_valid_literal_value(schema, inner, arg_value)
},
TypeType::NonNull(ref inner) => {
if arg_value.is_null() {
false
} else {
is_valid_literal_value(schema, inner, arg_value)
}
}
TypeType::List(ref inner) => match *arg_value {
InputValue::List(ref items) => items
.iter()
@ -35,47 +37,49 @@ where
match *arg_value {
InputValue::Null | InputValue::Variable(_) => true,
ref v @ InputValue::Scalar(_)
| ref v @ InputValue::Enum(_) => if let Some(parse_fn) = t.input_value_parse_fn() {
parse_fn(v)
} else {
false
},
ref v @ InputValue::Scalar(_) | ref v @ InputValue::Enum(_) => {
if let Some(parse_fn) = t.input_value_parse_fn() {
parse_fn(v)
} else {
false
}
}
InputValue::List(_) => false,
InputValue::Object(ref obj) => if let MetaType::InputObject(InputObjectMeta {
ref input_fields,
..
}) = *t
{
let mut remaining_required_fields = input_fields
.iter()
.filter_map(|f| {
if f.arg_type.is_non_null() {
Some(&f.name)
} else {
None
}
})
.collect::<HashSet<_>>();
let all_types_ok = obj.iter().all(|&(ref key, ref value)| {
remaining_required_fields.remove(&key.item);
if let Some(ref arg_type) = input_fields
InputValue::Object(ref obj) => {
if let MetaType::InputObject(InputObjectMeta {
ref input_fields, ..
}) = *t
{
let mut remaining_required_fields = input_fields
.iter()
.filter(|f| f.name == key.item)
.map(|f| schema.make_type(&f.arg_type))
.next()
{
is_valid_literal_value(schema, arg_type, &value.item)
} else {
false
}
});
.filter_map(|f| {
if f.arg_type.is_non_null() {
Some(&f.name)
} else {
None
}
})
.collect::<HashSet<_>>();
all_types_ok && remaining_required_fields.is_empty()
} else {
false
},
let all_types_ok = obj.iter().all(|&(ref key, ref value)| {
remaining_required_fields.remove(&key.item);
if let Some(ref arg_type) = input_fields
.iter()
.filter(|f| f.name == key.item)
.map(|f| schema.make_type(&f.arg_type))
.next()
{
is_valid_literal_value(schema, arg_type, &value.item)
} else {
false
}
});
all_types_ok && remaining_required_fields.is_empty()
} else {
false
}
}
}
}
}

View file

@ -11,7 +11,8 @@ pub fn to_camel_case<'a>(s: &'a str) -> Cow<'a, str> {
if i > 0 && part.len() == 1 {
dest += Cow::Owned(part.to_uppercase());
} else if i > 0 && part.len() > 1 {
let first = part.chars()
let first = part
.chars()
.next()
.unwrap()
.to_uppercase()

View file

@ -93,18 +93,20 @@ where
let mut errors: Vec<RuleError> = vec![];
match *meta_type {
TypeType::NonNull(ref inner) => if value.is_null() {
errors.push(unification_error(
var_name,
var_pos,
&path,
&format!(r#"Expected "{}", found null"#, meta_type),
));
} else {
errors.append(&mut unify_value(
var_name, var_pos, value, inner, schema, path,
));
},
TypeType::NonNull(ref inner) => {
if value.is_null() {
errors.push(unification_error(
var_name,
var_pos,
&path,
&format!(r#"Expected "{}", found null"#, meta_type),
));
} else {
errors.append(&mut unify_value(
var_name, var_pos, value, inner, schema, path,
));
}
}
TypeType::List(ref inner) => {
if value.is_null() {
@ -112,16 +114,18 @@ where
}
match value.to_list_value() {
Some(l) => for (i, v) in l.iter().enumerate() {
errors.append(&mut unify_value(
var_name,
var_pos,
v,
inner,
schema,
Path::ArrayElement(i, &path),
));
},
Some(l) => {
for (i, v) in l.iter().enumerate() {
errors.append(&mut unify_value(
var_name,
var_pos,
v,
inner,
schema,
Path::ArrayElement(i, &path),
));
}
}
_ => errors.append(&mut unify_value(
var_name, var_pos, value, inner, schema, path,
)),

View file

@ -14,7 +14,6 @@ impl<'a, S> Visitor<'a, S> for FieldsOnCorrectType
where
S: ScalarValue,
{
fn enter_field(
&mut self,
context: &mut ValidatorContext<'a, S>,

View file

@ -18,7 +18,6 @@ impl<'a, S> Visitor<'a, S> for KnownDirectives
where
S: ScalarValue,
{
fn enter_operation_definition(
&mut self,
_: &mut ValidatorContext<'a, S>,

View file

@ -13,7 +13,6 @@ impl<'a, S> Visitor<'a, S> for KnownFragmentNames
where
S: ScalarValue,
{
fn enter_fragment_spread(
&mut self,
context: &mut ValidatorContext<'a, S>,

View file

@ -23,7 +23,8 @@ where
.filter(|d| match **d {
Definition::Operation(_) => true,
Definition::Fragment(_) => false,
}).count(),
})
.count(),
);
}

View file

@ -30,7 +30,6 @@ impl<'a, S> Visitor<'a, S> for NoFragmentCycles<'a>
where
S: ScalarValue,
{
fn exit_document(&mut self, ctx: &mut ValidatorContext<'a, S>, _: &'a Document<S>) {
assert!(self.current_fragment.is_none());

View file

@ -79,7 +79,8 @@ where
&error_message(var.item, *op_name),
&[var.start.clone(), pos.clone()],
)
}).collect(),
})
.collect(),
);
}
}
@ -144,7 +145,8 @@ where
.iter()
.map(|&var_name| {
Spanning::start_end(&value.start.clone(), &value.end.clone(), var_name)
}).collect(),
})
.collect(),
);
}
}

View file

@ -515,14 +515,16 @@ impl<'a, S: Debug> OverlappingFieldsCanBeMerged<'a, S> {
conflicts
.iter()
.flat_map(|&Conflict(_, ref fs1, _)| fs1.clone()),
).collect(),
)
.collect(),
vec![pos2.clone()]
.into_iter()
.chain(
conflicts
.iter()
.flat_map(|&Conflict(_, _, ref fs2)| fs2.clone()),
).collect(),
)
.collect(),
))
}
@ -653,9 +655,11 @@ impl<'a, S: Debug> OverlappingFieldsCanBeMerged<'a, S> {
Selection::FragmentSpread(Spanning {
item: FragmentSpread { ref name, .. },
..
}) => if fragment_names.iter().find(|n| *n == &name.item).is_none() {
fragment_names.push(name.item);
},
}) => {
if fragment_names.iter().find(|n| *n == &name.item).is_none() {
fragment_names.push(name.item);
}
}
Selection::InlineFragment(Spanning {
item: ref inline, ..
}) => {
@ -725,7 +729,8 @@ fn format_reason(reason: &ConflictReasonMessage) -> String {
name,
format_reason(subreason)
)
}).collect::<Vec<_>>()
})
.collect::<Vec<_>>()
.join(" and "),
}
}
@ -1004,7 +1009,10 @@ mod tests {
}
"#,
&[RuleError::new(
&error_message("x", &Message("name and barks are different fields".to_owned())),
&error_message(
"x",
&Message("name and barks are different fields".to_owned()),
),
&[
SourcePosition::new(101, 6, 12),
SourcePosition::new(163, 9, 12),
@ -1042,21 +1050,30 @@ mod tests {
"#,
&[
RuleError::new(
&error_message("x", &Message("name and barks are different fields".to_owned())),
&error_message(
"x",
&Message("name and barks are different fields".to_owned()),
),
&[
SourcePosition::new(235, 13, 14),
SourcePosition::new(311, 17, 12),
],
),
RuleError::new(
&error_message("x", &Message("name and nickname are different fields".to_owned())),
&error_message(
"x",
&Message("name and nickname are different fields".to_owned()),
),
&[
SourcePosition::new(235, 13, 14),
SourcePosition::new(374, 20, 12),
],
),
RuleError::new(
&error_message("x", &Message("barks and nickname are different fields".to_owned())),
&error_message(
"x",
&Message("barks and nickname are different fields".to_owned()),
),
&[
SourcePosition::new(311, 17, 12),
SourcePosition::new(374, 20, 12),
@ -1495,7 +1512,8 @@ mod tests {
.interfaces(&[
registry.get_type::<NonNullStringBox1>(i),
registry.get_type::<SomeBox>(i),
]).into_meta()
])
.into_meta()
}
}
@ -1548,7 +1566,8 @@ mod tests {
.interfaces(&[
registry.get_type::<NonNullStringBox2>(i),
registry.get_type::<SomeBox>(i),
]).into_meta()
])
.into_meta()
}
}

View file

@ -21,7 +21,6 @@ impl<'a, S> Visitor<'a, S> for PossibleFragmentSpreads<'a, S>
where
S: ScalarValue,
{
fn enter_document(&mut self, ctx: &mut ValidatorContext<'a, S>, defs: &'a Document<S>) {
for def in defs {
if let Definition::Fragment(Spanning { ref item, .. }) = *def {

View file

@ -24,13 +24,13 @@ where
}) = ctx.parent_type().and_then(|t| t.field_by_name(field_name))
{
for meta_arg in meta_args {
if meta_arg.arg_type.is_non_null() && field
.item
.arguments
.as_ref()
.and_then(|args| {
args.item.get(&meta_arg.name)
}).is_none()
if meta_arg.arg_type.is_non_null()
&& field
.item
.arguments
.as_ref()
.and_then(|args| args.item.get(&meta_arg.name))
.is_none()
{
ctx.report_error(
&field_error_message(
@ -58,12 +58,13 @@ where
}) = ctx.schema.directive_by_name(directive_name)
{
for meta_arg in meta_args {
if meta_arg.arg_type.is_non_null() && directive
.item
.arguments
.as_ref()
.and_then(|args| args.item.get(&meta_arg.name))
.is_none()
if meta_arg.arg_type.is_non_null()
&& directive
.item
.arguments
.as_ref()
.and_then(|args| args.item.get(&meta_arg.name))
.is_none()
{
ctx.report_error(
&directive_error_message(

View file

@ -13,12 +13,7 @@ impl<'a, S> Visitor<'a, S> for ScalarLeafs
where
S: ScalarValue,
{
fn enter_field(
&mut self,
ctx: &mut ValidatorContext<'a, S>,
field: &'a Spanning<Field<S>>,
) {
fn enter_field(&mut self, ctx: &mut ValidatorContext<'a, S>, field: &'a Spanning<Field<S>>) {
let field_name = &field.item.name.item;
let error = if let (Some(field_type), Some(field_type_literal)) =

View file

@ -19,20 +19,11 @@ impl<'a, S> Visitor<'a, S> for UniqueArgumentNames<'a>
where
S: ScalarValue,
{
fn enter_directive(
&mut self,
_: &mut ValidatorContext<'a, S>,
_: &'a Spanning<Directive<S>>,
) {
fn enter_directive(&mut self, _: &mut ValidatorContext<'a, S>, _: &'a Spanning<Directive<S>>) {
self.known_names = HashMap::new();
}
fn enter_field(
&mut self,
_: &mut ValidatorContext<'a, S>,
_: &'a Spanning<Field<S>>,
) {
fn enter_field(&mut self, _: &mut ValidatorContext<'a, S>, _: &'a Spanning<Field<S>>) {
self.known_names = HashMap::new();
}

View file

@ -19,7 +19,6 @@ impl<'a, S> Visitor<'a, S> for UniqueFragmentNames<'a>
where
S: ScalarValue,
{
fn enter_fragment_definition(
&mut self,
context: &mut ValidatorContext<'a, S>,

View file

@ -19,7 +19,6 @@ impl<'a, S> Visitor<'a, S> for UniqueOperationNames<'a>
where
S: ScalarValue,
{
fn enter_operation_definition(
&mut self,
ctx: &mut ValidatorContext<'a, S>,

View file

@ -19,7 +19,6 @@ impl<'a, S> Visitor<'a, S> for UniqueVariableNames<'a>
where
S: ScalarValue,
{
fn enter_operation_definition(
&mut self,
_: &mut ValidatorContext<'a, S>,

View file

@ -156,7 +156,8 @@ where
EnumValue::new("HEEL"),
EnumValue::new("DOWN"),
],
).into_meta()
)
.into_meta()
}
}
@ -218,7 +219,8 @@ where
registry.get_type::<Being>(i),
registry.get_type::<Pet>(i),
registry.get_type::<Canine>(i),
]).into_meta()
])
.into_meta()
}
}
@ -247,7 +249,8 @@ where
EnumValue::new("TAN"),
EnumValue::new("SPOTTED"),
],
).into_meta()
)
.into_meta()
}
}
@ -377,7 +380,8 @@ where
.interfaces(&[
registry.get_type::<Being>(i),
registry.get_type::<Intelligent>(i),
]).into_meta()
])
.into_meta()
}
}
@ -410,7 +414,8 @@ where
.interfaces(&[
registry.get_type::<Being>(i),
registry.get_type::<Intelligent>(i),
]).into_meta()
])
.into_meta()
}
}
@ -768,6 +773,5 @@ fn print_errors(errs: &[RuleError]) {
print!("[{:>3},{:>3},{:>3}] ", p.index(), p.line(), p.column());
}
println!("{}", err.message());
}
}

View file

@ -305,23 +305,26 @@ fn visit_input_value<'a, S, V>(
enter_input_value(v, ctx, input_value);
match input_value.item {
InputValue::Object(ref fields) => for field in fields {
let inner_type = ctx
.current_input_type_literal()
.and_then(|t| match *t {
Type::NonNullNamed(ref name) | Type::Named(ref name) => {
ctx.schema.concrete_type_by_name(name)
}
_ => None,
}).and_then(|ct| ct.input_field_by_name(&field.0.item))
.map(|f| &f.arg_type);
InputValue::Object(ref fields) => {
for field in fields {
let inner_type = ctx
.current_input_type_literal()
.and_then(|t| match *t {
Type::NonNullNamed(ref name) | Type::Named(ref name) => {
ctx.schema.concrete_type_by_name(name)
}
_ => None,
})
.and_then(|ct| ct.input_field_by_name(&field.0.item))
.map(|f| &f.arg_type);
ctx.with_pushed_input_type(inner_type, |ctx| {
v.enter_object_field(ctx, field);
visit_input_value(v, ctx, &field.1);
v.exit_object_field(ctx, field);
})
},
ctx.with_pushed_input_type(inner_type, |ctx| {
v.enter_object_field(ctx, field);
visit_input_value(v, ctx, &field.1);
v.exit_object_field(ctx, field);
})
}
}
InputValue::List(ref ls) => {
let inner_type = ctx.current_input_type_literal().and_then(|t| match *t {
Type::List(ref inner) | Type::NonNullList(ref inner) => {

View file

@ -102,10 +102,7 @@ where
}
/// View the underlying float value, if present.
#[deprecated(
since = "0.11",
note = "Use `Value::as_scalar_value` instead"
)]
#[deprecated(since = "0.11", note = "Use `Value::as_scalar_value` instead")]
pub fn as_float_value(&self) -> Option<f64>
where
for<'a> &'a S: ScalarRefValue<'a>,
@ -146,10 +143,7 @@ where
}
/// View the underlying string value, if present.
#[deprecated(
since = "0.11",
note = "Use `Value::as_scalar_value` instead"
)]
#[deprecated(since = "0.11", note = "Use `Value::as_scalar_value` instead")]
pub fn as_string_value<'a>(&'a self) -> Option<&'a str>
where
Option<&'a String>: From<&'a S>,
@ -175,7 +169,8 @@ impl<S: ScalarValue> ToInputValue<S> for Value<S> {
Spanning::unlocated(k.clone()),
Spanning::unlocated(v.to_input_value()),
)
}).collect(),
})
.collect(),
),
}
}

View file

@ -246,7 +246,8 @@ where
+ Into<Option<&'a i32>>
+ Into<Option<&'a String>>
+ Into<Option<&'a f64>>,
{}
{
}
/// The default scalar value representation in juniper
///

View file

@ -1,4 +1,4 @@
use proc_macro2::{TokenStream};
use proc_macro2::TokenStream;
use syn;
use syn::{Data, DeriveInput, Fields, Variant};
@ -139,8 +139,8 @@ pub fn impl_enum(ast: &syn::DeriveInput, is_internal: bool) -> TokenStream {
let name = attrs.name.unwrap_or(ast.ident.to_string());
let meta_description = match attrs.description {
Some(descr) => quote!{ let meta = meta.description(#descr); },
None => quote!{ let meta = meta; },
Some(descr) => quote! { let meta = meta.description(#descr); },
None => quote! { let meta = meta; },
};
let mut values = TokenStream::new();
@ -167,21 +167,21 @@ pub fn impl_enum(ast: &syn::DeriveInput, is_internal: bool) -> TokenStream {
.name
.unwrap_or(::util::to_upper_snake_case(&variant.ident.to_string()));
let descr = match var_attrs.description {
Some(s) => quote!{ Some(#s.to_string()) },
None => quote!{ None },
Some(s) => quote! { Some(#s.to_string()) },
None => quote! { None },
};
let depr = match var_attrs.deprecation {
Some(DeprecationAttr { reason: Some(s) }) => quote!{
Some(DeprecationAttr { reason: Some(s) }) => quote! {
#juniper_path::meta::DeprecationStatus::Deprecated(Some(#s.to_string()))
},
Some(DeprecationAttr { reason: None }) => quote!{
Some(DeprecationAttr { reason: None }) => quote! {
#juniper_path::meta::DeprecationStatus::Deprecated(None)
},
None => quote!{
None => quote! {
#juniper_path::meta::DeprecationStatus::Current
},
};
values.extend(quote!{
values.extend(quote! {
#juniper_path::meta::EnumValue{
name: #name.to_string(),
description: #descr,
@ -190,17 +190,17 @@ pub fn impl_enum(ast: &syn::DeriveInput, is_internal: bool) -> TokenStream {
});
// Build resolve match clause.
resolves.extend(quote!{
resolves.extend(quote! {
&#ident::#var_ident => #juniper_path::Value::scalar(String::from(#name)),
});
// Build from_input clause.
from_inputs.extend(quote!{
from_inputs.extend(quote! {
Some(#name) => Some(#ident::#var_ident),
});
// Build to_input clause.
to_inputs.extend(quote!{
to_inputs.extend(quote! {
&#ident::#var_ident =>
#juniper_path::InputValue::scalar(#name.to_string()),
});

View file

@ -149,8 +149,8 @@ pub fn impl_input_object(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre
let generics = &ast.generics;
let meta_description = match attrs.description {
Some(descr) => quote!{ let meta = meta.description(#descr); },
None => quote!{ let meta = meta; },
Some(descr) => quote! { let meta = meta.description(#descr); },
None => quote! { let meta = meta; },
};
let mut meta_fields = TokenStream::new();
@ -174,8 +174,8 @@ pub fn impl_input_object(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre
}
};
let field_description = match field_attrs.description {
Some(s) => quote!{ let field = field.description(#s); },
None => quote!{},
Some(s) => quote! { let field = field.description(#s); },
None => quote! {},
};
let default = {
@ -205,17 +205,17 @@ pub fn impl_input_object(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre
let create_meta_field = match default {
Some(ref def) => {
quote!{
quote! {
let field = registry.arg_with_default::<#field_ty>( #name, &#def, &());
}
}
None => {
quote!{
quote! {
let field = registry.arg::<#field_ty>(#name, &());
}
}
};
meta_fields.extend(quote!{
meta_fields.extend(quote! {
{
#create_meta_field
#field_description
@ -227,11 +227,11 @@ pub fn impl_input_object(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre
let from_input_default = match default {
Some(ref def) => {
quote!{
quote! {
Some(&&#juniper_path::InputValue::Null) | None if true => #def,
}
}
None => quote!{},
None => quote! {},
};
from_inputs.extend(quote!{
@ -249,7 +249,7 @@ pub fn impl_input_object(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre
});
// Build to_input clause.
to_inputs.extend(quote!{
to_inputs.extend(quote! {
(#name, self.#field_ident.to_input_value()),
});
}
@ -332,5 +332,5 @@ pub fn impl_input_object(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre
}
};
body
body
}

View file

@ -147,8 +147,8 @@ pub fn impl_object(ast: &syn::DeriveInput) -> TokenStream {
let attrs = ObjAttrs::from_input(ast);
let name = attrs.name.unwrap_or(ast.ident.to_string());
let build_description = match attrs.description {
Some(s) => quote!{ builder.description(#s) },
None => quote!{ builder },
Some(s) => quote! { builder.description(#s) },
None => quote! { builder },
};
let mut meta_fields = TokenStream::new();
@ -176,17 +176,17 @@ pub fn impl_object(ast: &syn::DeriveInput) -> TokenStream {
}
};
let build_description = match field_attrs.description {
Some(s) => quote!{ field.description(#s) },
None => quote!{ field },
Some(s) => quote! { field.description(#s) },
None => quote! { field },
};
let build_deprecation = match field_attrs.deprecation {
Some(DeprecationAttr { reason: Some(s) }) => quote!{ field.deprecated(Some(#s)) },
Some(DeprecationAttr { reason: None }) => quote!{ field.deprecated(None) },
None => quote!{ field },
Some(DeprecationAttr { reason: Some(s) }) => quote! { field.deprecated(Some(#s)) },
Some(DeprecationAttr { reason: None }) => quote! { field.deprecated(None) },
None => quote! { field },
};
meta_fields.extend(quote!{
meta_fields.extend(quote! {
{
let field = registry.field::<#field_ty>(#name, &());
let field = #build_description;
@ -197,7 +197,7 @@ pub fn impl_object(ast: &syn::DeriveInput) -> TokenStream {
// Build from_input clause.
resolvers.extend(quote!{
resolvers.extend(quote! {
#name => executor.resolve_with_ctx(&(), &self.#field_ident),
});
}

View file

@ -1,4 +1,4 @@
use proc_macro2::{TokenStream};
use proc_macro2::TokenStream;
use syn::{self, Data, Fields, Ident, Variant};
@ -22,7 +22,7 @@ pub fn impl_scalar_value(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre
let display = derive_display(variants.iter(), ident);
quote!{
quote! {
#(#froms)*
#serialize
@ -39,7 +39,7 @@ where
quote!(#ident::#variant(ref v) => write!(f, "{}", v),)
});
quote!{
quote! {
impl std::fmt::Display for #ident {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
@ -65,7 +65,7 @@ where
quote!(juniper::serde)
};
quote!{
quote! {
impl #serde_path::Serialize for #ident {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where S: #serde_path::Serializer
@ -91,7 +91,7 @@ fn derive_from_variant(variant: &Variant, ident: &Ident) -> Result<TokenStream,
let variant = &variant.ident;
Ok(quote!{
Ok(quote! {
impl std::convert::From<#ty> for #ident {
fn from(t: #ty) -> Self {
#ident::#variant(t)

View file

@ -34,14 +34,14 @@ pub fn get_deprecated(attrs: &Vec<Attribute>) -> Option<DeprecationAttr> {
fn get_deprecated_meta_list(list: &MetaList) -> DeprecationAttr {
for meta in &list.nested {
match meta {
&NestedMeta::Meta(Meta::NameValue(ref nv)) if nv.ident == "note" => {
match &nv.lit {
&Lit::Str(ref strlit) => {
return DeprecationAttr { reason: Some(strlit.value().to_string()) };
}
_ => panic!("deprecated attribute note value only has string literal"),
&NestedMeta::Meta(Meta::NameValue(ref nv)) if nv.ident == "note" => match &nv.lit {
&Lit::Str(ref strlit) => {
return DeprecationAttr {
reason: Some(strlit.value().to_string()),
};
}
}
_ => panic!("deprecated attribute note value only has string literal"),
},
_ => {}
}
}
@ -60,7 +60,8 @@ pub fn get_doc_comment(attrs: &Vec<Attribute>) -> Option<String> {
// Concatenates doc strings into one string.
fn join_doc_strings(docs: &Vec<String>) -> String {
let s: String = docs.iter()
let s: String = docs
.iter()
// Trim any extra spaces.
.map(|x| x.trim().to_string())
// Convert empty comments to newlines.
@ -118,7 +119,11 @@ pub fn get_graphql_attr(attrs: &Vec<Attribute>) -> Option<Vec<NestedMeta>> {
None
}
pub fn keyed_item_value(item: &NestedMeta, name: &str, validation: AttributeValidation) -> Option<AttributeValue> {
pub fn keyed_item_value(
item: &NestedMeta,
name: &str,
validation: AttributeValidation,
) -> Option<AttributeValue> {
match item {
// Attributes in the form of `#[graphql(name = "value")]`.
&NestedMeta::Meta(Meta::NameValue(ref nameval)) if nameval.ident == name => {
@ -130,23 +135,21 @@ pub fn keyed_item_value(item: &NestedMeta, name: &str, validation: AttributeVali
"Invalid format for attribute \"{:?}\": expected a bare attribute without a value",
item
));
},
}
_ => Some(AttributeValue::String(strlit.value())),
},
_ => None,
_ => None,
}
},
}
// Attributes in the form of `#[graphql(name)]`.
&NestedMeta::Meta(Meta::Word(ref ident)) if ident.to_string() == name => {
match validation {
AttributeValidation::String => {
panic!(format!(
&NestedMeta::Meta(Meta::Word(ref ident)) if ident.to_string() == name => match validation {
AttributeValidation::String => {
panic!(format!(
"Invalid format for attribute \"{:?}\": expected a string value",
item
));
},
_ => Some(AttributeValue::Bare),
item
));
}
_ => Some(AttributeValue::Bare),
},
_ => None,
}
@ -161,7 +164,8 @@ pub fn to_camel_case(s: &str) -> String {
if i > 0 && part.len() == 1 {
dest.push_str(&part.to_uppercase());
} else if i > 0 && part.len() > 1 {
let first = part.chars()
let first = part
.chars()
.next()
.unwrap()
.to_uppercase()

View file

@ -50,11 +50,13 @@ where
.unwrap_or(Err(GraphQLRequestError::Invalid(
"'query' parameter is missing".to_string(),
))),
).and_then(move |gql_req| {
)
.and_then(move |gql_req| {
execute_request(root_node, context, gql_req).map_err(|_| {
unreachable!("thread pool has shut down?!");
})
}).or_else(|err| future::ok(render_error(err))),
})
.or_else(|err| future::ok(render_error(err))),
)),
&Method::POST => Either::A(Either::B(
request
@ -70,11 +72,13 @@ where
.map_err(GraphQLRequestError::BodyJSONError)
})
})
}).and_then(move |gql_req| {
})
.and_then(move |gql_req| {
execute_request(root_node, context, gql_req).map_err(|_| {
unreachable!("thread pool has shut down?!");
})
}).or_else(|err| future::ok(render_error(err))),
})
.or_else(|err| future::ok(render_error(err))),
)),
_ => return Either::B(future::ok(new_response(StatusCode::METHOD_NOT_ALLOWED))),
}
@ -239,7 +243,8 @@ where
let body = serde_json::to_string_pretty(&res).unwrap();
Ok(Async::Ready((is_ok, body)))
})
})).map(|results| {
}))
.map(|results| {
let is_ok = results.iter().all(|&(is_ok, _)| is_ok);
// concatenate json bodies as array
// TODO: maybe use Body chunks instead?

View file

@ -488,7 +488,8 @@ mod tests {
.get_raw("content-type")
.expect("No content type header from handler")[0]
.clone(),
).expect("Content-type header invalid UTF-8");
)
.expect("Content-type header invalid UTF-8");
let body = response::extract_body_to_string(response);
http_tests::TestResponse {

View file

@ -2,7 +2,8 @@
extern crate juniper;
extern crate juniper_rocket;
#[macro_use] extern crate rocket;
#[macro_use]
extern crate rocket;
use rocket::response::content;
use rocket::State;

View file

@ -300,7 +300,8 @@ where
}
impl<'v, S> FromFormValue<'v> for GraphQLRequest<S>
where S: ScalarValue
where
S: ScalarValue,
{
type Error = String;
@ -459,12 +460,12 @@ mod fromform_tests {
#[cfg(test)]
mod tests {
use rocket::{self, get, post, routes};
use rocket::request::Form;
use rocket::http::ContentType;
use rocket::local::{Client, LocalRequest};
use rocket::request::Form;
use rocket::Rocket;
use rocket::State;
use rocket::{self, get, post, routes};
use juniper::http::tests as http_tests;
use juniper::tests::model::Database;
@ -522,7 +523,8 @@ mod tests {
.manage(Schema::new(
Database::new(),
EmptyMutation::<Database>::new(),
)).mount("/", routes![post_graphql_handler, get_graphql_handler])
))
.mount("/", routes![post_graphql_handler, get_graphql_handler])
}
fn make_test_response(request: &LocalRequest) -> http_tests::TestResponse {

View file

@ -43,5 +43,6 @@ fn main() {
.or(homepage)
.or(warp::path("graphql").and(graphql_filter))
.with(log),
).run(([127, 0, 0, 1], 8080));
)
.run(([127, 0, 0, 1], 8080));
}

View file

@ -201,7 +201,8 @@ where
let response = request.execute(&schema, &context);
Ok((serde_json::to_vec(&response)?, response.is_ok()))
})
}).and_then(|result| ::futures::future::done(Ok(build_response(result))))
})
.and_then(|result| ::futures::future::done(Ok(build_response(result))))
.map_err(|e: tokio_threadpool::BlockingError| warp::reject::custom(e)),
)
};
@ -234,7 +235,8 @@ where
let response = graphql_request.execute(&schema, &context);
Ok((serde_json::to_vec(&response)?, response.is_ok()))
})
}).and_then(|result| ::futures::future::done(Ok(build_response(result))))
})
.and_then(|result| ::futures::future::done(Ok(build_response(result))))
.map_err(|e: tokio_threadpool::BlockingError| warp::reject::custom(e)),
)
};
@ -396,7 +398,8 @@ mod tests {
{ "variables": null, "query": "{ hero(episode: NEW_HOPE) { name } }" },
{ "variables": null, "query": "{ hero(episode: EMPIRE) { id name } }" }
]"##,
).reply(&filter);
)
.reply(&filter);
assert_eq!(response.status(), http::StatusCode::OK);
assert_eq!(