Add support for return statements in field resolver functions

This commit is contained in:
Magnus Hallin 2016-11-30 21:49:50 +01:00
parent ca3832c6c2
commit 46764de1a6
4 changed files with 14 additions and 5 deletions

View file

@ -26,9 +26,9 @@ mod field_execution {
graphql_object!(DeepDataType: () |&self| {
field a() -> &str { "Already Been Done" }
field b() -> &str { "Boring" }
field c() -> &[Option<&str>] { &[Some("Contrived"), None, Some("Confusing")] }
field c() -> Vec<Option<&str>> { vec![Some("Contrived"), None, Some("Confusing")] }
field deeper() -> &[Option<DataType>] { &[Some(DataType), None, Some(DataType) ] }
field deeper() -> Vec<Option<DataType>> { vec![Some(DataType), None, Some(DataType) ] }
});
#[test]

View file

@ -69,13 +69,13 @@ macro_rules! __graphql__build_field_matches {
) => {
$(
if $fieldvar == &$crate::to_snake_case(stringify!($name)) {
let result: $t = {
let result: $t = (|| {
__graphql__args!(
@assign_arg_vars,
$argsvar, $executorvar, $($args)*
);
$body
};
})();
return ($crate::IntoFieldResult::into(result)).and_then(|r| $executorvar.resolve(&r))
}

View file

@ -3,6 +3,7 @@ use std::collections::HashMap;
use value::Value;
use ast::InputValue;
use schema::model::RootNode;
use executor::FieldResult;
struct Interface;
struct Root;
@ -14,6 +15,8 @@ Syntax to validate:
* Object vs. interface
* Description vs. no description
* Deprecated vs. not deprecated
* FieldResult vs. object directly
* Return vs. implicit return
*/
@ -28,6 +31,12 @@ graphql_object!(Root: () |&self| {
field deprecated "Deprecation reason"
deprecated_descr() -> i64 as "Field description" { 0 }
field with_field_result() -> FieldResult<i64> { Ok(0) }
field with_return() -> i64 { return 0; }
field with_return_field_result() -> FieldResult<i64> { return Ok(0); }
interfaces: [Interface]
});

View file

@ -84,7 +84,7 @@ graphql_object!(<'a> TypeType<'a>: SchemaType as "__Type" |&self| {
}
}
field of_type() -> Option<&TypeType> {
field of_type() -> Option<&Box<TypeType>> {
match *self {
TypeType::Concrete(_) => None,
TypeType::List(ref l) | TypeType::NonNull(ref l) => Some(l),