Allow crate type paths in resolve
for graphql_scalar!
(#229)
Fixes https://github.com/graphql-rust/juniper/issues/227.
This commit is contained in:
parent
08c31357af
commit
45004f77a3
2 changed files with 18 additions and 4 deletions
|
@ -59,7 +59,7 @@ macro_rules! graphql_scalar {
|
||||||
@generate,
|
@generate,
|
||||||
( $name:ty, $outname:expr, $descr:tt ),
|
( $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 )
|
( $fiv_arg:ident, $fiv_result:ty, $fiv_body:block )
|
||||||
)
|
)
|
||||||
) => {
|
) => {
|
||||||
|
@ -85,7 +85,7 @@ macro_rules! graphql_scalar {
|
||||||
&$resolve_selfvar,
|
&$resolve_selfvar,
|
||||||
_: &(),
|
_: &(),
|
||||||
_: Option<&[$crate::Selection]>,
|
_: Option<&[$crate::Selection]>,
|
||||||
_: &$crate::Executor<Self::Context>) -> $crate::Value {
|
_: &$crate::Executor<Self::Context>) -> $resolve_retval {
|
||||||
$resolve_body
|
$resolve_body
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,9 +117,9 @@ macro_rules! graphql_scalar {
|
||||||
@parse,
|
@parse,
|
||||||
$meta:tt,
|
$meta:tt,
|
||||||
( $_ignored:tt, $fiv: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) -> ... { ... }
|
// from_input_value(arg: &InputValue) -> ... { ... }
|
||||||
|
|
|
@ -92,6 +92,20 @@ where
|
||||||
f(type_info);
|
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]
|
#[test]
|
||||||
fn default_name_introspection() {
|
fn default_name_introspection() {
|
||||||
let doc = r#"
|
let doc = r#"
|
||||||
|
|
Loading…
Reference in a new issue