Skip to content

Commit

Permalink
Replace try! with ?
Browse files Browse the repository at this point in the history
  • Loading branch information
Atul9 committed Jan 22, 2018
1 parent bfe2ef5 commit a7d843e
Show file tree
Hide file tree
Showing 14 changed files with 260 additions and 213 deletions.
14 changes: 7 additions & 7 deletions juniper/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,25 +432,25 @@ impl fmt::Display for InputValue {
InputValue::Enum(ref v) => write!(f, "{}", v),
InputValue::Variable(ref v) => write!(f, "${}", v),
InputValue::List(ref v) => {
try!(write!(f, "["));
write!(f, "[")?;

for (i, spanning) in v.iter().enumerate() {
try!(spanning.item.fmt(f));
spanning.item.fmt(f)?;
if i < v.len() - 1 {
try!(write!(f, ", "));
write!(f, ", ")?;
}
}

write!(f, "]")
}
InputValue::Object(ref o) => {
try!(write!(f, "{{"));
write!(f, "{{")?;

for (i, &(ref k, ref v)) in o.iter().enumerate() {
try!(write!(f, "{}: ", k.item));
try!(v.item.fmt(f));
write!(f, "{}: ", k.item)?;
v.item.fmt(f)?;
if i < o.len() - 1 {
try!(write!(f, ", "));
write!(f, ", ")?;
}
}

Expand Down
3 changes: 2 additions & 1 deletion juniper/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ impl<'a, T: GraphQLType, C> IntoResolvable<'a, T, C> for FieldResult<(&'a T::Con
}

impl<'a, T: GraphQLType, C> IntoResolvable<'a, Option<T>, C>
for FieldResult<Option<(&'a T::Context, T)>> {
for FieldResult<Option<(&'a T::Context, T)>>
{
fn into(self, _: &'a C) -> FieldResult<Option<(&'a T::Context, Option<T>)>> {
self.map(|o| o.map(|(ctx, v)| (ctx, Some(v))))
}
Expand Down
12 changes: 8 additions & 4 deletions juniper/src/executor_tests/introspection/input_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,19 @@ pub struct NamedPublic {
#[derive(GraphQLInputObject, Debug)]
#[graphql(_internal)]
struct FieldDescription {
#[graphql(description = "The first field")] field_one: String,
#[graphql(description = "The second field")] field_two: String,
#[graphql(description = "The first field")]
field_one: String,
#[graphql(description = "The second field")]
field_two: String,
}

#[derive(GraphQLInputObject, Debug)]
#[graphql(_internal)]
struct FieldWithDefaults {
#[graphql(default = "123")] field_one: i32,
#[graphql(default = "456", description = "The second field")] field_two: i32,
#[graphql(default = "123")]
field_one: i32,
#[graphql(default = "456", description = "The second field")]
field_two: i32,
}

graphql_object!(Root: () |&self| {
Expand Down
3 changes: 2 additions & 1 deletion juniper/src/executor_tests/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ struct ExampleInputObject {
#[derive(GraphQLInputObject, Debug)]
#[graphql(_internal)]
struct InputWithDefaults {
#[graphql(default = "123")] a: i32,
#[graphql(default = "123")]
a: i32,
}

graphql_object!(TestType: () |&self| {
Expand Down
19 changes: 10 additions & 9 deletions juniper/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use executor::ExecutionError;
#[derive(Deserialize, Clone, Serialize, PartialEq, Debug)]
pub struct GraphQLRequest {
query: String,
#[serde(rename = "operationName")] operation_name: Option<String>,
#[serde(rename = "operationName")]
operation_name: Option<String>,
variables: Option<InputValue>,
}

Expand Down Expand Up @@ -101,22 +102,22 @@ impl<'a> ser::Serialize for GraphQLResponse<'a> {
{
match self.0 {
Ok((ref res, ref err)) => {
let mut map = try!(serializer.serialize_map(None));
let mut map = serializer.serialize_map(None)?;

try!(map.serialize_key("data"));
try!(map.serialize_value(res));
map.serialize_key("data")?;
map.serialize_value(res)?;

if !err.is_empty() {
try!(map.serialize_key("errors"));
try!(map.serialize_value(err));
map.serialize_key("errors")?;
map.serialize_value(err)?;
}

map.end()
}
Err(ref err) => {
let mut map = try!(serializer.serialize_map(Some(1)));
try!(map.serialize_key("errors"));
try!(map.serialize_value(err));
let mut map = serializer.serialize_map(Some(1))?;
map.serialize_key("errors")?;
map.serialize_value(err)?;
map.end()
}
}
Expand Down
52 changes: 26 additions & 26 deletions juniper/src/integrations/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ impl ser::Serialize for ExecutionError {
where
S: ser::Serializer,
{
let mut map = try!(serializer.serialize_map(Some(4)));
let mut map = serializer.serialize_map(Some(4))?;

try!(map.serialize_key("message"));
try!(map.serialize_value(self.error().message()));
map.serialize_key("message")?;
map.serialize_value(self.error().message())?;

let locations = vec![self.location()];
try!(map.serialize_key("locations"));
try!(map.serialize_value(&locations));
map.serialize_key("locations")?;
map.serialize_value(&locations)?;

try!(map.serialize_key("path"));
try!(map.serialize_value(self.path()));
map.serialize_key("path")?;
map.serialize_value(self.path())?;

if !self.error().data().is_null() {
try!(map.serialize_key("data"));
try!(map.serialize_value(self.error().data()));
map.serialize_key("data")?;
map.serialize_value(self.error().data())?;
}

map.end()
Expand Down Expand Up @@ -123,7 +123,7 @@ impl<'de> de::Deserialize<'de> for InputValue {
{
let mut values = Vec::new();

while let Some(el) = try!(visitor.next_element()) {
while let Some(el) = visitor.next_element()? {
values.push(el);
}

Expand All @@ -136,7 +136,7 @@ impl<'de> de::Deserialize<'de> for InputValue {
{
let mut values: OrderMap<String, InputValue> = OrderMap::new();

while let Some((key, value)) = try!(visitor.next_entry()) {
while let Some((key, value)) = visitor.next_entry()? {
values.insert(key, value);
}

Expand Down Expand Up @@ -176,13 +176,13 @@ impl ser::Serialize for RuleError {
where
S: ser::Serializer,
{
let mut map = try!(serializer.serialize_map(Some(2)));
let mut map = serializer.serialize_map(Some(2))?;

try!(map.serialize_key("message"));
try!(map.serialize_value(self.message()));
map.serialize_key("message")?;
map.serialize_value(self.message())?;

try!(map.serialize_key("locations"));
try!(map.serialize_value(self.locations()));
map.serialize_key("locations")?;
map.serialize_value(self.locations())?;

map.end()
}
Expand All @@ -193,15 +193,15 @@ impl ser::Serialize for SourcePosition {
where
S: ser::Serializer,
{
let mut map = try!(serializer.serialize_map(Some(2)));
let mut map = serializer.serialize_map(Some(2))?;

let line = self.line() + 1;
try!(map.serialize_key("line"));
try!(map.serialize_value(&line));
map.serialize_key("line")?;
map.serialize_value(&line)?;

let column = self.column() + 1;
try!(map.serialize_key("column"));
try!(map.serialize_value(&column));
map.serialize_key("column")?;
map.serialize_value(&column)?;

map.end()
}
Expand All @@ -212,20 +212,20 @@ impl<'a> ser::Serialize for Spanning<ParseError<'a>> {
where
S: ser::Serializer,
{
let mut map = try!(serializer.serialize_map(Some(2)));
let mut map = serializer.serialize_map(Some(2))?;

let message = format!("{}", self.item);
try!(map.serialize_key("message"));
try!(map.serialize_value(&message));
map.serialize_key("message")?;
map.serialize_value(&message)?;

let mut location = OrderMap::new();
location.insert("line".to_owned(), self.start.line() + 1);
location.insert("column".to_owned(), self.start.column() + 1);

let locations = vec![location];

try!(map.serialize_key("locations"));
try!(map.serialize_value(&locations));
map.serialize_key("locations")?;
map.serialize_value(&locations)?;

map.end()
}
Expand Down
2 changes: 1 addition & 1 deletion juniper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ where
QueryT: GraphQLType<Context = CtxT>,
MutationT: GraphQLType<Context = CtxT>,
{
let document = try!(parse_document_source(document_source));
let document = parse_document_source(document_source)?;

{
let errors = validate_input_values(variables, &document, &root_node.schema);
Expand Down
Loading

0 comments on commit a7d843e

Please sign in to comment.