Allow crate type paths in resolve for graphql_scalar! (#229)

Fixes https://github.com/graphql-rust/juniper/issues/227.
This commit is contained in:
Christian Legnitto 2018-08-27 15:26:33 -07:00 committed by GitHub
parent 08c31357af
commit 45004f77a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 4 deletions

View file

@ -59,7 +59,7 @@ macro_rules! graphql_scalar {
@generate,
( $name:ty, $outname:expr, $descr:tt ),
(
( $resolve_selfvar:ident, $resolve_body:block ),
( $resolve_selfvar:ident, $resolve_retval:ty, $resolve_body:block ),
( $fiv_arg:ident, $fiv_result:ty, $fiv_body:block )
)
) => {
@ -85,7 +85,7 @@ macro_rules! graphql_scalar {
&$resolve_selfvar,
_: &(),
_: Option<&[$crate::Selection]>,
_: &$crate::Executor<Self::Context>) -> $crate::Value {
_: &$crate::Executor<Self::Context>) -> $resolve_retval {
$resolve_body
}
}
@ -117,9 +117,9 @@ macro_rules! graphql_scalar {
@parse,
$meta:tt,
( $_ignored:tt, $fiv:tt ),
resolve(&$selfvar:ident) -> Value $body:block $($rest:tt)*
resolve(&$selfvar:ident) -> $retval:ty $body:block $($rest:tt)*
) => {
graphql_scalar!( @parse, $meta, ( ($selfvar, $body), $fiv ), $($rest)* );
graphql_scalar!( @parse, $meta, ( ($selfvar, $retval, $body), $fiv ), $($rest)* );
};
// from_input_value(arg: &InputValue) -> ... { ... }

View file

@ -92,6 +92,20 @@ where
f(type_info);
}
#[test]
fn path_in_resolve_return_type() {
struct ResolvePath(i32);
graphql_scalar!(ResolvePath {
resolve(&self) -> self::Value {
Value::int(self.0)
}
from_input_value(v: &InputValue) -> Option<ResolvePath> {
v.as_int_value().map(|i| ResolvePath(i))
}
});
}
#[test]
fn default_name_introspection() {
let doc = r#"