Add support for return statements in field resolver functions
This commit is contained in:
parent
ca3832c6c2
commit
46764de1a6
4 changed files with 14 additions and 5 deletions
src
|
@ -26,9 +26,9 @@ mod field_execution {
|
||||||
graphql_object!(DeepDataType: () |&self| {
|
graphql_object!(DeepDataType: () |&self| {
|
||||||
field a() -> &str { "Already Been Done" }
|
field a() -> &str { "Already Been Done" }
|
||||||
field b() -> &str { "Boring" }
|
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]
|
#[test]
|
||||||
|
|
|
@ -69,13 +69,13 @@ macro_rules! __graphql__build_field_matches {
|
||||||
) => {
|
) => {
|
||||||
$(
|
$(
|
||||||
if $fieldvar == &$crate::to_snake_case(stringify!($name)) {
|
if $fieldvar == &$crate::to_snake_case(stringify!($name)) {
|
||||||
let result: $t = {
|
let result: $t = (|| {
|
||||||
__graphql__args!(
|
__graphql__args!(
|
||||||
@assign_arg_vars,
|
@assign_arg_vars,
|
||||||
$argsvar, $executorvar, $($args)*
|
$argsvar, $executorvar, $($args)*
|
||||||
);
|
);
|
||||||
$body
|
$body
|
||||||
};
|
})();
|
||||||
|
|
||||||
return ($crate::IntoFieldResult::into(result)).and_then(|r| $executorvar.resolve(&r))
|
return ($crate::IntoFieldResult::into(result)).and_then(|r| $executorvar.resolve(&r))
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ use std::collections::HashMap;
|
||||||
use value::Value;
|
use value::Value;
|
||||||
use ast::InputValue;
|
use ast::InputValue;
|
||||||
use schema::model::RootNode;
|
use schema::model::RootNode;
|
||||||
|
use executor::FieldResult;
|
||||||
|
|
||||||
struct Interface;
|
struct Interface;
|
||||||
struct Root;
|
struct Root;
|
||||||
|
@ -14,6 +15,8 @@ Syntax to validate:
|
||||||
* Object vs. interface
|
* Object vs. interface
|
||||||
* Description vs. no description
|
* Description vs. no description
|
||||||
* Deprecated vs. not deprecated
|
* Deprecated vs. not deprecated
|
||||||
|
* FieldResult vs. object directly
|
||||||
|
* Return vs. implicit return
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -28,6 +31,12 @@ graphql_object!(Root: () |&self| {
|
||||||
field deprecated "Deprecation reason"
|
field deprecated "Deprecation reason"
|
||||||
deprecated_descr() -> i64 as "Field description" { 0 }
|
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]
|
interfaces: [Interface]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
match *self {
|
||||||
TypeType::Concrete(_) => None,
|
TypeType::Concrete(_) => None,
|
||||||
TypeType::List(ref l) | TypeType::NonNull(ref l) => Some(l),
|
TypeType::List(ref l) | TypeType::NonNull(ref l) => Some(l),
|
||||||
|
|
Loading…
Add table
Reference in a new issue