#[macro_export(local_inner_macros)]
macro_rules! graphql_interface {
( @as_item, $i:item) => { $i };
( @as_expr, $e:expr) => { $e };
(
@ gather_meta,
($reg:expr, $acc:expr, $info:expr, $descr:expr),
field deprecated $reason:tt
$name:ident
$args:tt -> $t:ty as $desc:tt
$body:block
$( $rest:tt )*
) => {
$acc.push(__graphql__args!(
@apply_args,
$reg,
$reg.field_convert::<$t, _, Self::Context>(
&$crate::to_camel_case(__graphql__stringify!($name)), $info)
.description($desc)
.deprecated($reason),
$info,
$args));
graphql_interface!(@ gather_meta, ($reg, $acc, $info, $descr), $( $rest )*);
};
(
@ gather_meta,
($reg:expr, $acc:expr, $info:expr, $descr:expr),
field deprecated $reason:tt $name:ident $args:tt -> $t:ty $body:block $( $rest:tt )*
) => {
$acc.push(__graphql__args!(
@apply_args,
$reg,
$reg.field_convert::<$t, _, Self::Context>(
&$crate::to_camel_case(__graphql__stringify!($name)), $info)
.deprecated($reason),
$info,
$args));
graphql_interface!(@ gather_meta, ($reg, $acc, $info, $descr), $( $rest )*);
};
(
@gather_meta,
($reg:expr, $acc:expr, $info:expr, $descr:expr),
field $name:ident $args:tt -> $t:ty as $desc:tt $body:block $( $rest:tt )*
) => {
$acc.push(__graphql__args!(
@apply_args,
$reg,
$reg.field_convert::<$t, _, Self::Context>(
&$crate::to_camel_case(__graphql__stringify!($name)), $info)
.description($desc),
$info,
$args));
graphql_interface!(@ gather_meta, ($reg, $acc, $info, $descr), $( $rest )*);
};
(
@ gather_meta,
($reg:expr, $acc:expr, $info:expr, $descr:expr),
field $name:ident $args:tt -> $t:ty $body:block $( $rest:tt )*
) => {
$acc.push(__graphql__args!(
@apply_args,
$reg,
$reg.field_convert::<$t, _, Self::Context>(
&$crate::to_camel_case(__graphql__stringify!($name)), $info),
$info,
$args));
graphql_interface!(@ gather_meta, ($reg, $acc, $info, $descr), $( $rest )*);
};
(
@ gather_meta,
($reg:expr, $acc:expr, $info:expr, $descr:expr),
description : $value:tt $( $rest:tt )*
) => {
$descr = Some(graphql_interface!(@as_expr, $value));
graphql_interface!(@gather_meta, ($reg, $acc, $info, $descr), $( $rest )*)
};
(
@ gather_meta,
($reg:expr, $acc:expr, $info:expr, $descr:expr),
instance_resolvers : | $ctxtvar:pat
| { $( $srctype:ty => $resolver:expr ),* $(,)* } $( $rest:tt )*
) => {
$(
let _ = $reg.get_type::<$srctype>(&());
)*
graphql_interface!(@gather_meta, ($reg, $acc, $info, $descr), $( $rest )*)
};
(
@ concrete_type_name,
($outname:tt, $ctxtarg:ident, $ctxttype:ty),
instance_resolvers : | $ctxtvar:pat
| { $( $srctype:ty => $resolver:expr ),* $(,)* } $( $rest:tt )*
) => {
let $ctxtvar = &$ctxtarg;
$(
if ($resolver as Option<$srctype>).is_some() {
return (<$srctype as $crate::GraphQLType>::name(&())).unwrap().to_owned();
}
)*
__graphql__panic!("Concrete type not handled by instance resolvers on {}", $outname);
};
(
@ resolve_into_type,
($outname:tt, $typenamearg:ident, $execarg:ident, $ctxttype:ty),
instance_resolvers : | $ctxtvar:pat
| { $( $srctype:ty => $resolver:expr ),* $(,)* } $( $rest:tt )*
) => {
let $ctxtvar = &$execarg.context();
$(
if $typenamearg == (<$srctype as $crate::GraphQLType>::name(&())).unwrap() {
return $execarg.resolve(&(), &$resolver);
}
)*
__graphql__panic!("Concrete type not handled by instance resolvers on {}", $outname);
};
( @ $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 | {
$( $items:tt )*
}
) => {
graphql_interface!(@as_item, impl<$($lifetime)*> $crate::GraphQLType for $name {
type Context = $ctxt;
type TypeInfo = ();
fn name(_: &()) -> Option<&str> {
Some($outname)
}
#[allow(unused_assignments)]
#[allow(unused_mut)]
fn meta<'r>(
info: &(),
registry: &mut $crate::Registry<'r>
) -> $crate::meta::MetaType<'r> {
let mut fields = Vec::new();
let mut description = None;
graphql_interface!(
@ gather_meta, (registry, fields, info, description), $($items)*
);
let mut mt = registry.build_interface_type::<$name>(&(), &fields);
if let Some(description) = description {
mt = mt.description(description);
}
mt.into_meta()
}
#[allow(unused_variables)]
#[allow(unused_mut)]
fn resolve_field(
&$mainself,
info: &(),
field: &str,
args: &$crate::Arguments,
mut executor: &$crate::Executor<Self::Context>
) -> $crate::ExecutionResult {
__graphql__build_field_matches!(
($outname, $mainself, field, args, executor),
(),
$($items)*);
}
fn concrete_type_name(&$mainself, context: &Self::Context, _info: &()) -> String {
graphql_interface!(
@ concrete_type_name,
($outname, context, $ctxt),
$($items)*);
}
fn resolve_into_type(
&$mainself,
_: &(),
type_name: &str,
_: Option<&[$crate::Selection]>,
executor: &$crate::Executor<Self::Context>,
)
-> $crate::ExecutionResult
{
graphql_interface!(
@ resolve_into_type,
($outname, type_name, executor, $ctxt),
$($items)*);
}
});
};
(
<$($lifetime:tt),*> $name:ty : $ctxt:ty as $outname:tt | &$mainself:ident | {
$( $items:tt )*
}
) => {
graphql_interface!(
($($lifetime),*) $name : $ctxt as $outname | &$mainself | { $( $items )* });
};
(
$name:ty : $ctxt:ty as $outname:tt | &$mainself:ident | {
$( $items:tt )*
}
) => {
graphql_interface!(() $name : $ctxt as $outname | &$mainself | { $( $items )* });
};
(
$name:ty : $ctxt:ty | &$mainself:ident | {
$( $items:tt )*
}
) => {
graphql_interface!(() $name : $ctxt as (__graphql__stringify!($name)) | &$mainself | { $( $items )* });
};
}