Skip to content

Commit 46764de

Browse files
committed
Add support for return statements in field resolver functions
1 parent ca3832c commit 46764de

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

src/executor_tests/executor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ mod field_execution {
2626
graphql_object!(DeepDataType: () |&self| {
2727
field a() -> &str { "Already Been Done" }
2828
field b() -> &str { "Boring" }
29-
field c() -> &[Option<&str>] { &[Some("Contrived"), None, Some("Confusing")] }
29+
field c() -> Vec<Option<&str>> { vec![Some("Contrived"), None, Some("Confusing")] }
3030

31-
field deeper() -> &[Option<DataType>] { &[Some(DataType), None, Some(DataType) ] }
31+
field deeper() -> Vec<Option<DataType>> { vec![Some(DataType), None, Some(DataType) ] }
3232
});
3333

3434
#[test]

src/macros/field.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ macro_rules! __graphql__build_field_matches {
6969
) => {
7070
$(
7171
if $fieldvar == &$crate::to_snake_case(stringify!($name)) {
72-
let result: $t = {
72+
let result: $t = (|| {
7373
__graphql__args!(
7474
@assign_arg_vars,
7575
$argsvar, $executorvar, $($args)*
7676
);
7777
$body
78-
};
78+
})();
7979

8080
return ($crate::IntoFieldResult::into(result)).and_then(|r| $executorvar.resolve(&r))
8181
}

src/macros/tests/field.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::collections::HashMap;
33
use value::Value;
44
use ast::InputValue;
55
use schema::model::RootNode;
6+
use executor::FieldResult;
67

78
struct Interface;
89
struct Root;
@@ -14,6 +15,8 @@ Syntax to validate:
1415
* Object vs. interface
1516
* Description vs. no description
1617
* Deprecated vs. not deprecated
18+
* FieldResult vs. object directly
19+
* Return vs. implicit return
1720
1821
*/
1922

@@ -28,6 +31,12 @@ graphql_object!(Root: () |&self| {
2831
field deprecated "Deprecation reason"
2932
deprecated_descr() -> i64 as "Field description" { 0 }
3033

34+
field with_field_result() -> FieldResult<i64> { Ok(0) }
35+
36+
field with_return() -> i64 { return 0; }
37+
38+
field with_return_field_result() -> FieldResult<i64> { return Ok(0); }
39+
3140
interfaces: [Interface]
3241
});
3342

src/schema/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ graphql_object!(<'a> TypeType<'a>: SchemaType as "__Type" |&self| {
8484
}
8585
}
8686

87-
field of_type() -> Option<&TypeType> {
87+
field of_type() -> Option<&Box<TypeType>> {
8888
match *self {
8989
TypeType::Concrete(_) => None,
9090
TypeType::List(ref l) | TypeType::NonNull(ref l) => Some(l),

0 commit comments

Comments
 (0)