Update syntax of interface instance resolvers
This commit is contained in:
parent
d59e6c2f2e
commit
612a3af001
8 changed files with 81 additions and 185 deletions
|
@ -36,9 +36,9 @@ graphql_interface!(Interface: () as "SampleInterface" |&self| {
|
||||||
Sample::One
|
Sample::One
|
||||||
}
|
}
|
||||||
|
|
||||||
instance_resolvers: |&_| [
|
instance_resolvers: |&_| {
|
||||||
Some(Root {}),
|
Root => Some(Root {}),
|
||||||
]
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
graphql_object!(Root: () as "Root" |&self| {
|
graphql_object!(Root: () as "Root" |&self| {
|
||||||
|
|
|
@ -22,10 +22,10 @@ with an array of expressions, each resolving into an `Option<T>` of the possible
|
||||||
instances:
|
instances:
|
||||||
|
|
||||||
```rust,ignore
|
```rust,ignore
|
||||||
instance_resolvers: |&context| [
|
instance_resolvers: |&context| {
|
||||||
context.get_human(self.id()), // returns Option<Human>
|
Human => context.get_human(self.id()), // returns Option<Human>
|
||||||
context.get_droid(self.id()), // returns Option<Droid>
|
Droid => context.get_droid(self.id()), // returns Option<Droid>
|
||||||
],
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
Each item in the array will be executed in order when the concrete type is
|
Each item in the array will be executed in order when the concrete type is
|
||||||
|
@ -70,10 +70,10 @@ graphql_object!(Droid: Database as "Droid" |&self| {
|
||||||
graphql_interface!(<'a> &'a Character: Database as "Character" |&self| {
|
graphql_interface!(<'a> &'a Character: Database as "Character" |&self| {
|
||||||
field id() -> &str { self.id() }
|
field id() -> &str { self.id() }
|
||||||
|
|
||||||
instance_resolvers: |&context| [
|
instance_resolvers: |&context| {
|
||||||
context.humans.get(self.id()),
|
Human => context.humans.get(self.id()),
|
||||||
context.droids.get(self.id()),
|
Droid => context.droids.get(self.id()),
|
||||||
]
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
# fn main() { }
|
# fn main() { }
|
||||||
|
@ -89,8 +89,8 @@ macro_rules! graphql_interface {
|
||||||
|
|
||||||
// field deprecated <reason> <name>(...) -> <type> as <description> { ... }
|
// field deprecated <reason> <name>(...) -> <type> as <description> { ... }
|
||||||
(
|
(
|
||||||
@gather_meta,
|
@ gather_meta,
|
||||||
$reg:expr, $acc:expr, $descr:expr,
|
($reg:expr, $acc:expr, $descr:expr),
|
||||||
field deprecated $reason:tt $name:ident $args:tt -> $t:ty as $desc:tt $body:block $( $rest:tt )*
|
field deprecated $reason:tt $name:ident $args:tt -> $t:ty as $desc:tt $body:block $( $rest:tt )*
|
||||||
) => {
|
) => {
|
||||||
$acc.push(__graphql__args!(
|
$acc.push(__graphql__args!(
|
||||||
|
@ -102,13 +102,13 @@ macro_rules! graphql_interface {
|
||||||
.deprecated($reason),
|
.deprecated($reason),
|
||||||
$args));
|
$args));
|
||||||
|
|
||||||
graphql_interface!(@gather_meta, $reg, $acc, $descr, $( $rest )*);
|
graphql_interface!(@ gather_meta, ($reg, $acc, $descr), $( $rest )*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// field deprecated <reason> <name>(...) -> <type> { ... }
|
// field deprecated <reason> <name>(...) -> <type> { ... }
|
||||||
(
|
(
|
||||||
@gather_meta,
|
@ gather_meta,
|
||||||
$reg:expr, $acc:expr, $descr:expr,
|
($reg:expr, $acc:expr, $descr:expr),
|
||||||
field deprecated $reason:tt $name:ident $args:tt -> $t:ty $body:block $( $rest:tt )*
|
field deprecated $reason:tt $name:ident $args:tt -> $t:ty $body:block $( $rest:tt )*
|
||||||
) => {
|
) => {
|
||||||
$acc.push(__graphql__args!(
|
$acc.push(__graphql__args!(
|
||||||
|
@ -119,13 +119,13 @@ macro_rules! graphql_interface {
|
||||||
.deprecated($reason),
|
.deprecated($reason),
|
||||||
$args));
|
$args));
|
||||||
|
|
||||||
graphql_interface!(@gather_meta, $reg, $acc, $descr, $( $rest )*);
|
graphql_interface!(@ gather_meta, ($reg, $acc, $descr), $( $rest )*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// field <name>(...) -> <type> as <description> { ... }
|
// field <name>(...) -> <type> as <description> { ... }
|
||||||
(
|
(
|
||||||
@gather_meta,
|
@gather_meta,
|
||||||
$reg:expr, $acc:expr, $descr:expr,
|
($reg:expr, $acc:expr, $descr:expr),
|
||||||
field $name:ident $args:tt -> $t:ty as $desc:tt $body:block $( $rest:tt )*
|
field $name:ident $args:tt -> $t:ty as $desc:tt $body:block $( $rest:tt )*
|
||||||
) => {
|
) => {
|
||||||
$acc.push(__graphql__args!(
|
$acc.push(__graphql__args!(
|
||||||
|
@ -136,13 +136,13 @@ macro_rules! graphql_interface {
|
||||||
.description($desc),
|
.description($desc),
|
||||||
$args));
|
$args));
|
||||||
|
|
||||||
graphql_interface!(@gather_meta, $reg, $acc, $descr, $( $rest )*);
|
graphql_interface!(@ gather_meta, ($reg, $acc, $descr), $( $rest )*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// field <name>(...) -> <type> { ... }
|
// field <name>(...) -> <type> { ... }
|
||||||
(
|
(
|
||||||
@gather_meta,
|
@ gather_meta,
|
||||||
$reg:expr, $acc:expr, $descr:expr,
|
($reg:expr, $acc:expr, $descr:expr),
|
||||||
field $name:ident $args:tt -> $t:ty $body:block $( $rest:tt )*
|
field $name:ident $args:tt -> $t:ty $body:block $( $rest:tt )*
|
||||||
) => {
|
) => {
|
||||||
$acc.push(__graphql__args!(
|
$acc.push(__graphql__args!(
|
||||||
|
@ -152,176 +152,60 @@ macro_rules! graphql_interface {
|
||||||
&$crate::to_snake_case(stringify!($name))),
|
&$crate::to_snake_case(stringify!($name))),
|
||||||
$args));
|
$args));
|
||||||
|
|
||||||
graphql_interface!(@gather_meta, $reg, $acc, $descr, $( $rest )*);
|
graphql_interface!(@ gather_meta, ($reg, $acc, $descr), $( $rest )*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// description: <description>
|
// description: <description>
|
||||||
(
|
(
|
||||||
@gather_meta,
|
@ gather_meta,
|
||||||
$reg:expr, $acc:expr, $descr:expr,
|
($reg:expr, $acc:expr, $descr:expr),
|
||||||
description : $value:tt $( $rest:tt )*
|
description : $value:tt $( $rest:tt )*
|
||||||
) => {
|
) => {
|
||||||
$descr = Some(graphql_interface!(@as_expr, $value));
|
$descr = Some(graphql_interface!(@as_expr, $value));
|
||||||
|
|
||||||
graphql_interface!(@gather_meta, $reg, $acc, $descr, $( $rest )*)
|
graphql_interface!(@gather_meta, ($reg, $acc, $descr), $( $rest )*)
|
||||||
};
|
};
|
||||||
|
|
||||||
// instance_resolvers: | <ctxtvar> | [...]
|
// instance_resolvers: | <ctxtvar> | [...]
|
||||||
(
|
(
|
||||||
@gather_meta,
|
@ concrete_type_name,
|
||||||
$reg:expr, $acc:expr, $descr:expr,
|
|
||||||
instance_resolvers: | $ctxtvar:pat | $resolvers:tt $( $rest:tt )*
|
|
||||||
) => {
|
|
||||||
graphql_interface!(@gather_meta, $reg, $acc, $descr, $( $rest )*)
|
|
||||||
};
|
|
||||||
|
|
||||||
( @gather_meta, $reg:expr, $acc:expr, $descr:expr, , $( $rest:tt )* ) => {
|
|
||||||
graphql_interface!(@gather_meta, $reg, $acc, $descr, $( $rest )*)
|
|
||||||
};
|
|
||||||
|
|
||||||
( @gather_meta, $reg:expr, $acc:expr, $descr:expr, ) => {
|
|
||||||
};
|
|
||||||
|
|
||||||
// field deprecated <reason> <name>(...) -> <type> as <description> { ... }
|
|
||||||
(
|
|
||||||
@resolve_into_type,
|
|
||||||
$buildargs:tt,
|
|
||||||
field deprecated $reason:tt $name:ident $args:tt -> $t:ty as $descr:tt $body:block $( $rest:tt )*
|
|
||||||
) => {
|
|
||||||
graphql_interface!(@resolve_into_type, $buildargs, $( $rest )*)
|
|
||||||
};
|
|
||||||
|
|
||||||
// field deprecated <reason> <name>(...) -> <type> { ... }
|
|
||||||
(
|
|
||||||
@resolve_into_type,
|
|
||||||
$buildargs:tt,
|
|
||||||
field deprecated $reason:tt $name:ident $args:tt -> $t:ty $body:block $( $rest:tt )*
|
|
||||||
) => {
|
|
||||||
graphql_interface!(@resolve_into_type, $buildargs, $( $rest )*)
|
|
||||||
};
|
|
||||||
|
|
||||||
// field <name>(...) -> <type> as <description> { ... }
|
|
||||||
(
|
|
||||||
@resolve_into_type,
|
|
||||||
$buildargs:tt,
|
|
||||||
field $name:ident $args:tt -> $t:ty as $descr:tt $body:block $( $rest:tt )*
|
|
||||||
) => {
|
|
||||||
graphql_interface!(@resolve_into_type, $buildargs, $( $rest )*)
|
|
||||||
};
|
|
||||||
|
|
||||||
// field <name>(...) -> <type> { ... }
|
|
||||||
(
|
|
||||||
@resolve_into_type,
|
|
||||||
$buildargs:tt,
|
|
||||||
field $name:ident $args:tt -> $t:ty $body:block $( $rest:tt )*
|
|
||||||
) => {
|
|
||||||
graphql_interface!(@resolve_into_type, $buildargs, $( $rest )*)
|
|
||||||
};
|
|
||||||
|
|
||||||
// description: <description>
|
|
||||||
(
|
|
||||||
@resolve_into_type,
|
|
||||||
$buildargs:tt, description : $value:tt $( $rest:tt )*
|
|
||||||
) => {
|
|
||||||
graphql_interface!(@resolve_into_type, $buildargs, $( $rest )*)
|
|
||||||
};
|
|
||||||
|
|
||||||
// field deprecated <reason> <name>(...) -> <type> as <description> { ... }
|
|
||||||
(
|
|
||||||
@concrete_type_name,
|
|
||||||
$buildargs:tt,
|
|
||||||
field deprecated $reason:tt $name:ident $args:tt -> $t:ty as $descr:tt $body:block $( $rest:tt )*
|
|
||||||
) => {
|
|
||||||
graphql_interface!(@concrete_type_name, $buildargs, $( $rest )*)
|
|
||||||
};
|
|
||||||
|
|
||||||
// field deprecated <reason> <name>(...) -> <type> { ... }
|
|
||||||
(
|
|
||||||
@concrete_type_name,
|
|
||||||
$buildargs:tt,
|
|
||||||
field deprecated $reason:tt $name:ident $args:tt -> $t:ty $body:block $( $rest:tt )*
|
|
||||||
) => {
|
|
||||||
graphql_interface!(@concrete_type_name, $buildargs, $( $rest )*)
|
|
||||||
};
|
|
||||||
|
|
||||||
// field <name>(...) -> <type> as <description> { ... }
|
|
||||||
(
|
|
||||||
@concrete_type_name,
|
|
||||||
$buildargs:tt,
|
|
||||||
field $name:ident $args:tt -> $t:ty as $descr:tt $body:block $( $rest:tt )*
|
|
||||||
) => {
|
|
||||||
graphql_interface!(@concrete_type_name, $buildargs, $( $rest )*)
|
|
||||||
};
|
|
||||||
|
|
||||||
// field <name>(...) -> <type> { ... }
|
|
||||||
(
|
|
||||||
@concrete_type_name,
|
|
||||||
$buildargs:tt,
|
|
||||||
field $name:ident $args:tt -> $t:ty $body:block $( $rest:tt )*
|
|
||||||
) => {
|
|
||||||
graphql_interface!(@concrete_type_name, $buildargs, $( $rest )*)
|
|
||||||
};
|
|
||||||
|
|
||||||
// description: <description>
|
|
||||||
(
|
|
||||||
@concrete_type_name,
|
|
||||||
$buildargs:tt, description : $value:tt $( $rest:tt )*
|
|
||||||
) => {
|
|
||||||
graphql_interface!(@concrete_type_name, $buildargs, $( $rest )*)
|
|
||||||
};
|
|
||||||
|
|
||||||
// instance_resolvers: | <ctxtvar> | [...]
|
|
||||||
(
|
|
||||||
@concrete_type_name,
|
|
||||||
($outname:tt, $ctxtarg:ident, $ctxttype:ty),
|
($outname:tt, $ctxtarg:ident, $ctxttype:ty),
|
||||||
instance_resolvers : | $ctxtvar:pat | [ $( $resolver:expr ),* $(,)* ] $( $rest:tt )*
|
instance_resolvers : | $ctxtvar:pat | { $( $srctype:ty => $resolver:expr ),* $(,)* } $( $rest:tt )*
|
||||||
) => {
|
) => {
|
||||||
let $ctxtvar = &$ctxtarg;
|
let $ctxtvar = &$ctxtarg;
|
||||||
|
|
||||||
fn inner_type_of<T>(_: T) -> String where T: $crate::GraphQLType<$ctxttype> {
|
|
||||||
T::name().unwrap().to_owned()
|
|
||||||
}
|
|
||||||
|
|
||||||
$(
|
$(
|
||||||
if let Some(ref v) = $resolver {
|
if let Some(_) = $resolver {
|
||||||
return inner_type_of(v);
|
return (<$srctype as $crate::GraphQLType<$ctxttype>>::name()).unwrap().to_owned();
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
|
|
||||||
panic!("Concrete type not handled by instance resolvers on {}", $outname);
|
panic!("Concrete type not handled by instance resolvers on {}", $outname);
|
||||||
};
|
|
||||||
|
|
||||||
( @concrete_type_name, $buildargs:tt, ) => {
|
|
||||||
()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// instance_resolvers: | <ctxtvar> |
|
// instance_resolvers: | <ctxtvar> |
|
||||||
(
|
(
|
||||||
@resolve_into_type,
|
@ resolve_into_type,
|
||||||
($outname:tt, $typenamearg:ident, $execarg:ident, $ctxttype:ty),
|
($outname:tt, $typenamearg:ident, $execarg:ident, $ctxttype:ty),
|
||||||
instance_resolvers : | $ctxtvar:pat | [ $( $resolver:expr ),* $(,)* ] $( $rest:tt )*
|
instance_resolvers : | $ctxtvar:pat | { $( $srctype:ty => $resolver:expr ),* $(,)* } $( $rest:tt )*
|
||||||
) => {
|
) => {
|
||||||
let $ctxtvar = &$execarg.context();
|
let $ctxtvar = &$execarg.context();
|
||||||
|
|
||||||
fn inner_type_of<T>(_: T) -> String where T: $crate::GraphQLType<$ctxttype> {
|
|
||||||
T::name().unwrap().to_owned()
|
|
||||||
}
|
|
||||||
|
|
||||||
$(
|
$(
|
||||||
if let Some(ref v) = $resolver {
|
if $typenamearg == (<$srctype as $crate::GraphQLType<$ctxttype>>::name()).unwrap().to_owned() {
|
||||||
if inner_type_of(v) == $typenamearg {
|
return $execarg.resolve(&$resolver);
|
||||||
return $execarg.resolve(v);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
|
|
||||||
return Ok($crate::Value::null());
|
panic!("Concrete type not handled by instance resolvers on {}", $outname);
|
||||||
};
|
};
|
||||||
|
|
||||||
( @resolve_into_type, $buildargs:tt, ) => {
|
( @ $mfn:ident, $args:tt, $first:tt $($rest:tt)* ) => {
|
||||||
()
|
graphql_interface!(@ $mfn, $args, $($rest)*);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
( @ $mfn:ident, $buildargs:tt, ) => {};
|
||||||
|
|
||||||
(
|
(
|
||||||
( $($lifetime:tt),* ) $name:ty : $ctxt:ty as $outname:tt | &$mainself:ident | {
|
( $($lifetime:tt),* ) $name:ty : $ctxt:ty as $outname:tt | &$mainself:ident | {
|
||||||
$( $items:tt )*
|
$( $items:tt )*
|
||||||
|
@ -337,7 +221,7 @@ macro_rules! graphql_interface {
|
||||||
fn meta(registry: &mut $crate::Registry<$ctxt>) -> $crate::meta::MetaType {
|
fn meta(registry: &mut $crate::Registry<$ctxt>) -> $crate::meta::MetaType {
|
||||||
let mut fields = Vec::new();
|
let mut fields = Vec::new();
|
||||||
let mut description = None;
|
let mut description = None;
|
||||||
graphql_interface!(@gather_meta, registry, fields, description, $($items)*);
|
graphql_interface!(@ gather_meta, (registry, fields, description), $($items)*);
|
||||||
let mut mt = registry.build_interface_type::<$name>()(&fields);
|
let mut mt = registry.build_interface_type::<$name>()(&fields);
|
||||||
|
|
||||||
if let Some(description) = description {
|
if let Some(description) = description {
|
||||||
|
@ -350,19 +234,29 @@ macro_rules! graphql_interface {
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
fn resolve_field(&$mainself, field: &str, args: &$crate::Arguments, mut executor: &mut $crate::Executor<$ctxt>) -> $crate::ExecutionResult {
|
fn resolve_field(&$mainself, field: &str, args: &$crate::Arguments, mut executor: &mut $crate::Executor<$ctxt>) -> $crate::ExecutionResult {
|
||||||
__graphql__build_field_matches!(($outname, $mainself, field, args, executor), (), $($items)*);
|
__graphql__build_field_matches!(
|
||||||
|
($outname, $mainself, field, args, executor),
|
||||||
|
(),
|
||||||
|
$($items)*);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn concrete_type_name(&$mainself, context: &$ctxt) -> String {
|
fn concrete_type_name(&$mainself, context: &$ctxt) -> String {
|
||||||
graphql_interface!(
|
graphql_interface!(
|
||||||
@concrete_type_name,
|
@ concrete_type_name,
|
||||||
($outname, context, $ctxt),
|
($outname, context, $ctxt),
|
||||||
$($items)*);
|
$($items)*);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_into_type(&$mainself, type_name: &str, _: Option<Vec<$crate::Selection>>, executor: &mut $crate::Executor<$ctxt>) -> $crate::ExecutionResult {
|
fn resolve_into_type(
|
||||||
|
&$mainself,
|
||||||
|
type_name: &str,
|
||||||
|
_: Option<Vec<$crate::Selection>>,
|
||||||
|
executor: &mut $crate::Executor<$ctxt>,
|
||||||
|
)
|
||||||
|
-> $crate::ExecutionResult
|
||||||
|
{
|
||||||
graphql_interface!(
|
graphql_interface!(
|
||||||
@resolve_into_type,
|
@ resolve_into_type,
|
||||||
($outname, type_name, executor, $ctxt),
|
($outname, type_name, executor, $ctxt),
|
||||||
$($items)*);
|
$($items)*);
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,9 +100,9 @@ struct Implementor { id: String }
|
||||||
graphql_interface!(<'a> &'a Interface: () as "Interface" |&self| {
|
graphql_interface!(<'a> &'a Interface: () as "Interface" |&self| {
|
||||||
field id() -> &str { self.id() }
|
field id() -> &str { self.id() }
|
||||||
|
|
||||||
instance_resolvers: |&context| [
|
instance_resolvers: |&context| {
|
||||||
self.as_implementor(),
|
Implementor => self.as_implementor(),
|
||||||
]
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
graphql_object!(Implementor: () as "Implementor" |&self| {
|
graphql_object!(Implementor: () as "Implementor" |&self| {
|
||||||
|
|
|
@ -42,9 +42,9 @@ graphql_interface!(Interface: () as "Interface" |&self| {
|
||||||
field deprecated "Deprecation reason"
|
field deprecated "Deprecation reason"
|
||||||
deprecated_descr() -> i64 as "Field description" { 0 }
|
deprecated_descr() -> i64 as "Field description" { 0 }
|
||||||
|
|
||||||
instance_resolvers: |&_| [
|
instance_resolvers: |&_| {
|
||||||
Some(Root {}),
|
Root => Some(Root {}),
|
||||||
]
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
fn run_field_info_query<F>(type_name: &str, field_name: &str, f: F)
|
fn run_field_info_query<F>(type_name: &str, field_name: &str, f: F)
|
||||||
|
|
|
@ -45,18 +45,18 @@ graphql_object!(Concrete: () |&self| {
|
||||||
graphql_interface!(DefaultName: () |&self| {
|
graphql_interface!(DefaultName: () |&self| {
|
||||||
field simple() -> i64 { 0 }
|
field simple() -> i64 { 0 }
|
||||||
|
|
||||||
instance_resolvers: |_| [ Some(Concrete) ]
|
instance_resolvers: |_| { Concrete => Some(Concrete) }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
graphql_interface!(<'a> WithLifetime<'a>: () as "WithLifetime" |&self| {
|
graphql_interface!(<'a> WithLifetime<'a>: () as "WithLifetime" |&self| {
|
||||||
field simple() -> i64 { 0 }
|
field simple() -> i64 { 0 }
|
||||||
instance_resolvers: |_| [ Some(Concrete) ]
|
instance_resolvers: |_| { Concrete => Some(Concrete) }
|
||||||
});
|
});
|
||||||
|
|
||||||
graphql_interface!(<T> WithGenerics<T>: () as "WithGenerics" |&self| {
|
graphql_interface!(<T> WithGenerics<T>: () as "WithGenerics" |&self| {
|
||||||
field simple() -> i64 { 0 }
|
field simple() -> i64 { 0 }
|
||||||
instance_resolvers: |_| [ Some(Concrete) ]
|
instance_resolvers: |_| { Concrete => Some(Concrete) }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ graphql_interface!(DescriptionFirst: () as "DescriptionFirst" |&self| {
|
||||||
|
|
||||||
field simple() -> i64 { 0 }
|
field simple() -> i64 { 0 }
|
||||||
|
|
||||||
instance_resolvers: |_| [ Some(Concrete) ]
|
instance_resolvers: |_| { Concrete => Some(Concrete) }
|
||||||
});
|
});
|
||||||
|
|
||||||
graphql_interface!(FieldsFirst: () as "FieldsFirst" |&self| {
|
graphql_interface!(FieldsFirst: () as "FieldsFirst" |&self| {
|
||||||
|
@ -73,11 +73,11 @@ graphql_interface!(FieldsFirst: () as "FieldsFirst" |&self| {
|
||||||
|
|
||||||
description: "A description"
|
description: "A description"
|
||||||
|
|
||||||
instance_resolvers: |_| [ Some(Concrete) ]
|
instance_resolvers: |_| { Concrete => Some(Concrete) }
|
||||||
});
|
});
|
||||||
|
|
||||||
graphql_interface!(InterfacesFirst: () as "InterfacesFirst" |&self| {
|
graphql_interface!(InterfacesFirst: () as "InterfacesFirst" |&self| {
|
||||||
instance_resolvers: |_| [ Some(Concrete) ]
|
instance_resolvers: |_| { Concrete => Some(Concrete) }
|
||||||
|
|
||||||
field simple() -> i64 { 0 }
|
field simple() -> i64 { 0 }
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ graphql_interface!(InterfacesFirst: () as "InterfacesFirst" |&self| {
|
||||||
});
|
});
|
||||||
|
|
||||||
graphql_interface!(CommasWithTrailing: () as "CommasWithTrailing" |&self| {
|
graphql_interface!(CommasWithTrailing: () as "CommasWithTrailing" |&self| {
|
||||||
instance_resolvers: |_| [ Some(Concrete) ],
|
instance_resolvers: |_| { Concrete => Some(Concrete) },
|
||||||
|
|
||||||
field simple() -> i64 { 0 },
|
field simple() -> i64 { 0 },
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ graphql_interface!(CommasWithTrailing: () as "CommasWithTrailing" |&self| {
|
||||||
|
|
||||||
|
|
||||||
graphql_interface!(CommasOnMeta: () as "CommasOnMeta" |&self| {
|
graphql_interface!(CommasOnMeta: () as "CommasOnMeta" |&self| {
|
||||||
instance_resolvers: |_| [ Some(Concrete) ]
|
instance_resolvers: |_| { Concrete => Some(Concrete) }
|
||||||
description: "A description",
|
description: "A description",
|
||||||
|
|
||||||
field simple() -> i64 { 0 }
|
field simple() -> i64 { 0 }
|
||||||
|
@ -102,7 +102,7 @@ graphql_interface!(CommasOnMeta: () as "CommasOnMeta" |&self| {
|
||||||
|
|
||||||
|
|
||||||
graphql_interface!(ResolversWithTrailingComma: () as "ResolversWithTrailingComma" |&self| {
|
graphql_interface!(ResolversWithTrailingComma: () as "ResolversWithTrailingComma" |&self| {
|
||||||
instance_resolvers: |_| [ Some(Concrete), ]
|
instance_resolvers: |_| { Concrete => Some(Concrete), }
|
||||||
description: "A description",
|
description: "A description",
|
||||||
|
|
||||||
field simple() -> i64 { 0 }
|
field simple() -> i64 { 0 }
|
||||||
|
|
|
@ -52,9 +52,9 @@ graphql_object!(<T> WithGenerics<T>: () as "WithGenerics" |&self| {
|
||||||
graphql_interface!(Interface: () as "Interface" |&self| {
|
graphql_interface!(Interface: () as "Interface" |&self| {
|
||||||
field simple() -> i64 { 0 }
|
field simple() -> i64 { 0 }
|
||||||
|
|
||||||
instance_resolvers: |_| [
|
instance_resolvers: |_| {
|
||||||
Some(DescriptionFirst {}),
|
DescriptionFirst => Some(DescriptionFirst {}),
|
||||||
]
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
graphql_object!(DescriptionFirst: () as "DescriptionFirst" |&self| {
|
graphql_object!(DescriptionFirst: () as "DescriptionFirst" |&self| {
|
||||||
|
|
|
@ -37,7 +37,7 @@ macro_rules! graphql_union {
|
||||||
(
|
(
|
||||||
@ concrete_type_name,
|
@ concrete_type_name,
|
||||||
($outname:tt, $ctxtarg:ident, $ctxttype:ty),
|
($outname:tt, $ctxtarg:ident, $ctxttype:ty),
|
||||||
instance_resolvers: | $ctxtvar:pat | { $( $srctype:path => $resolver:expr ),* $(,)* } $( $rest:tt )*
|
instance_resolvers: | $ctxtvar:pat | { $( $srctype:ty => $resolver:expr ),* $(,)* } $( $rest:tt )*
|
||||||
) => {
|
) => {
|
||||||
let $ctxtvar = &$ctxtarg;
|
let $ctxtvar = &$ctxtarg;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ macro_rules! graphql_union {
|
||||||
(
|
(
|
||||||
@ resolve_into_type,
|
@ resolve_into_type,
|
||||||
($outname:tt, $typenamearg:ident, $execarg:ident, $ctxttype:ty),
|
($outname:tt, $typenamearg:ident, $execarg:ident, $ctxttype:ty),
|
||||||
instance_resolvers: | $ctxtvar:pat | { $( $srctype:path => $resolver:expr ),* $(,)* } $( $rest:tt )*
|
instance_resolvers: | $ctxtvar:pat | { $( $srctype:ty => $resolver:expr ),* $(,)* } $( $rest:tt )*
|
||||||
) => {
|
) => {
|
||||||
let $ctxtvar = &$execarg.context();
|
let $ctxtvar = &$execarg.context();
|
||||||
|
|
||||||
|
@ -118,7 +118,9 @@ macro_rules! graphql_union {
|
||||||
type_name: &str,
|
type_name: &str,
|
||||||
_: Option<Vec<$crate::Selection>>,
|
_: Option<Vec<$crate::Selection>>,
|
||||||
executor: &mut $crate::Executor<$ctxt>,
|
executor: &mut $crate::Executor<$ctxt>,
|
||||||
) -> $crate::ExecutionResult {
|
)
|
||||||
|
-> $crate::ExecutionResult
|
||||||
|
{
|
||||||
graphql_union!(
|
graphql_union!(
|
||||||
@ resolve_into_type,
|
@ resolve_into_type,
|
||||||
($outname, type_name, executor, $ctxt),
|
($outname, type_name, executor, $ctxt),
|
||||||
|
|
|
@ -26,10 +26,10 @@ graphql_interface!(<'a> &'a Character: Database as "Character" |&self| {
|
||||||
self.appears_in()
|
self.appears_in()
|
||||||
}
|
}
|
||||||
|
|
||||||
instance_resolvers: |&context| [
|
instance_resolvers: |&context| {
|
||||||
context.get_human(&self.id()),
|
&'a Human => context.get_human(&self.id()),
|
||||||
context.get_droid(&self.id()),
|
&'a Droid => context.get_droid(&self.id()),
|
||||||
]
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
graphql_object!(<'a> &'a Human: Database as "Human" |&self| {
|
graphql_object!(<'a> &'a Human: Database as "Human" |&self| {
|
||||||
|
|
Loading…
Reference in a new issue