2020-12-19 10:39:33 +00:00
|
|
|
use std::collections::HashSet;
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
use darling::ast::{Data, Style};
|
2020-03-06 15:58:43 +00:00
|
|
|
use proc_macro::TokenStream;
|
|
|
|
use proc_macro2::{Ident, Span};
|
|
|
|
use quote::quote;
|
2022-04-19 04:25:11 +00:00
|
|
|
use syn::{visit_mut::VisitMut, Error, Type};
|
2020-03-06 15:58:43 +00:00
|
|
|
|
2022-04-19 04:25:11 +00:00
|
|
|
use crate::{
|
|
|
|
args::{self, InterfaceField, InterfaceFieldArgument, RenameRuleExt, RenameTarget},
|
|
|
|
output_type::OutputType,
|
|
|
|
utils::{
|
|
|
|
gen_deprecation, generate_default, get_crate_name, get_rustdoc, visible_fn,
|
|
|
|
GeneratorResult, RemoveLifetime,
|
|
|
|
},
|
2021-02-27 03:59:58 +00:00
|
|
|
};
|
2020-10-16 02:45:27 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
pub fn generate(interface_args: &args::Interface) -> GeneratorResult<TokenStream> {
|
2020-03-06 15:58:43 +00:00
|
|
|
let crate_name = get_crate_name(interface_args.internal);
|
2020-09-28 09:44:00 +00:00
|
|
|
let ident = &interface_args.ident;
|
2021-01-14 03:27:15 +00:00
|
|
|
let (impl_generics, ty_generics, where_clause) = interface_args.generics.split_for_impl();
|
2020-09-28 09:44:00 +00:00
|
|
|
let s = match &interface_args.data {
|
2020-05-11 03:03:13 +00:00
|
|
|
Data::Enum(s) => s,
|
|
|
|
_ => {
|
2020-09-28 09:44:00 +00:00
|
|
|
return Err(
|
|
|
|
Error::new_spanned(ident, "Interface can only be applied to an enum.").into(),
|
|
|
|
)
|
2020-05-11 03:03:13 +00:00
|
|
|
}
|
2020-03-06 15:58:43 +00:00
|
|
|
};
|
2020-04-09 14:03:09 +00:00
|
|
|
let extends = interface_args.extends;
|
2020-03-06 15:58:43 +00:00
|
|
|
let mut enum_names = Vec::new();
|
2020-05-11 03:03:13 +00:00
|
|
|
let mut enum_items = HashSet::new();
|
2020-03-06 15:58:43 +00:00
|
|
|
let mut type_into_impls = Vec::new();
|
|
|
|
let gql_typename = interface_args
|
|
|
|
.name
|
|
|
|
.clone()
|
2020-10-14 09:08:57 +00:00
|
|
|
.unwrap_or_else(|| RenameTarget::Type.rename(ident.to_string()));
|
2020-05-10 04:41:05 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
let desc = get_rustdoc(&interface_args.attrs)?
|
2020-10-16 10:37:59 +00:00
|
|
|
.map(|s| quote! { ::std::option::Option::Some(#s) })
|
|
|
|
.unwrap_or_else(|| quote! {::std::option::Option::None});
|
2020-05-10 04:41:05 +00:00
|
|
|
|
2020-03-06 15:58:43 +00:00
|
|
|
let mut registry_types = Vec::new();
|
|
|
|
let mut possible_types = Vec::new();
|
2020-04-02 12:37:01 +00:00
|
|
|
let mut get_introspection_typename = Vec::new();
|
2020-09-12 09:29:52 +00:00
|
|
|
let mut collect_all_fields = Vec::new();
|
2020-03-06 15:58:43 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
for variant in s {
|
2020-05-11 03:03:13 +00:00
|
|
|
let enum_name = &variant.ident;
|
2020-09-28 09:44:00 +00:00
|
|
|
let ty = match variant.fields.style {
|
|
|
|
Style::Tuple if variant.fields.fields.len() == 1 => &variant.fields.fields[0],
|
|
|
|
Style::Tuple => {
|
2020-05-11 03:03:13 +00:00
|
|
|
return Err(Error::new_spanned(
|
2020-09-28 09:44:00 +00:00
|
|
|
enum_name,
|
2020-05-11 03:03:13 +00:00
|
|
|
"Only single value variants are supported",
|
2020-09-28 09:44:00 +00:00
|
|
|
)
|
|
|
|
.into())
|
2020-05-11 03:03:13 +00:00
|
|
|
}
|
2020-09-28 09:44:00 +00:00
|
|
|
Style::Unit => {
|
|
|
|
return Err(
|
|
|
|
Error::new_spanned(enum_name, "Empty variants are not supported").into(),
|
|
|
|
)
|
2020-05-11 03:03:13 +00:00
|
|
|
}
|
2020-09-28 09:44:00 +00:00
|
|
|
Style::Struct => {
|
2020-05-11 03:03:13 +00:00
|
|
|
return Err(Error::new_spanned(
|
2020-09-28 09:44:00 +00:00
|
|
|
enum_name,
|
2020-05-11 03:03:13 +00:00
|
|
|
"Variants with named fields are not supported",
|
2020-09-28 09:44:00 +00:00
|
|
|
)
|
|
|
|
.into())
|
2020-05-11 03:03:13 +00:00
|
|
|
}
|
|
|
|
};
|
2020-09-28 09:44:00 +00:00
|
|
|
|
|
|
|
if let Type::Path(p) = ty {
|
2020-05-11 03:03:13 +00:00
|
|
|
// This validates that the field type wasn't already used
|
2020-05-11 13:47:24 +00:00
|
|
|
if !enum_items.insert(p) {
|
2020-09-28 09:44:00 +00:00
|
|
|
return Err(
|
|
|
|
Error::new_spanned(ty, "This type already used in another variant").into(),
|
|
|
|
);
|
2020-05-11 03:03:13 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 22:27:31 +00:00
|
|
|
let mut assert_ty = p.clone();
|
|
|
|
RemoveLifetime.visit_type_path_mut(&mut assert_ty);
|
|
|
|
|
2020-05-11 03:03:13 +00:00
|
|
|
type_into_impls.push(quote! {
|
2020-10-24 01:08:18 +00:00
|
|
|
#crate_name::static_assertions::assert_impl_any!(#assert_ty: #crate_name::ObjectType, #crate_name::InterfaceType);
|
2020-10-14 22:27:31 +00:00
|
|
|
|
2020-06-28 06:28:53 +00:00
|
|
|
#[allow(clippy::all, clippy::pedantic)]
|
2021-01-14 03:27:15 +00:00
|
|
|
impl #impl_generics ::std::convert::From<#p> for #ident #ty_generics #where_clause {
|
2020-05-11 03:03:13 +00:00
|
|
|
fn from(obj: #p) -> Self {
|
|
|
|
#ident::#enum_name(obj)
|
2020-03-06 15:58:43 +00:00
|
|
|
}
|
2020-05-11 03:03:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
enum_names.push(enum_name);
|
2020-04-20 06:37:28 +00:00
|
|
|
|
2020-05-11 03:03:13 +00:00
|
|
|
registry_types.push(quote! {
|
2021-11-09 10:52:10 +00:00
|
|
|
<#p as #crate_name::OutputType>::create_type_info(registry);
|
|
|
|
registry.add_implements(&<#p as #crate_name::OutputType>::type_name(), #gql_typename);
|
2020-05-11 03:03:13 +00:00
|
|
|
});
|
2020-04-20 06:37:28 +00:00
|
|
|
|
2020-05-11 03:03:13 +00:00
|
|
|
possible_types.push(quote! {
|
2021-11-09 10:52:10 +00:00
|
|
|
possible_types.insert(<#p as #crate_name::OutputType>::type_name().into_owned());
|
2020-05-11 03:03:13 +00:00
|
|
|
});
|
2020-04-20 06:37:28 +00:00
|
|
|
|
2020-05-11 03:03:13 +00:00
|
|
|
get_introspection_typename.push(quote! {
|
2021-11-09 10:52:10 +00:00
|
|
|
#ident::#enum_name(obj) => <#p as #crate_name::OutputType>::type_name()
|
2020-09-12 09:29:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
collect_all_fields.push(quote! {
|
|
|
|
#ident::#enum_name(obj) => obj.collect_all_fields(ctx, fields)
|
|
|
|
});
|
2020-05-11 03:03:13 +00:00
|
|
|
} else {
|
2020-09-28 09:44:00 +00:00
|
|
|
return Err(Error::new_spanned(ty, "Invalid type").into());
|
2020-03-06 15:58:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut methods = Vec::new();
|
|
|
|
let mut schema_fields = Vec::new();
|
|
|
|
let mut resolvers = Vec::new();
|
|
|
|
|
2020-10-20 03:49:31 +00:00
|
|
|
if interface_args.fields.is_empty() {
|
|
|
|
return Err(Error::new_spanned(
|
|
|
|
&ident,
|
2020-10-22 02:11:47 +00:00
|
|
|
"A GraphQL Interface type must define one or more fields.",
|
2020-10-20 03:49:31 +00:00
|
|
|
)
|
|
|
|
.into());
|
|
|
|
}
|
|
|
|
|
2020-03-06 15:58:43 +00:00
|
|
|
for InterfaceField {
|
|
|
|
name,
|
2020-05-27 02:25:23 +00:00
|
|
|
method,
|
2020-03-06 15:58:43 +00:00
|
|
|
desc,
|
|
|
|
ty,
|
|
|
|
args,
|
|
|
|
deprecation,
|
2020-04-09 14:03:09 +00:00
|
|
|
external,
|
|
|
|
provides,
|
|
|
|
requires,
|
2020-12-11 08:03:28 +00:00
|
|
|
visible,
|
2020-03-06 15:58:43 +00:00
|
|
|
} in &interface_args.fields
|
|
|
|
{
|
2020-05-27 02:25:23 +00:00
|
|
|
let (name, method_name) = if let Some(method) = method {
|
|
|
|
(name.to_string(), Ident::new(method, Span::call_site()))
|
|
|
|
} else {
|
2021-07-31 15:54:16 +00:00
|
|
|
let method_name = Ident::new(name, Span::call_site());
|
2020-10-14 09:08:57 +00:00
|
|
|
(
|
|
|
|
interface_args
|
|
|
|
.rename_fields
|
2022-02-28 07:26:33 +00:00
|
|
|
.rename(name.as_ref(), RenameTarget::Field),
|
2020-10-14 09:08:57 +00:00
|
|
|
method_name,
|
|
|
|
)
|
2020-05-27 02:25:23 +00:00
|
|
|
};
|
2020-09-28 09:44:00 +00:00
|
|
|
let ty = match syn::parse_str::<syn::Type>(&ty.value()) {
|
|
|
|
Ok(ty) => ty,
|
|
|
|
Err(_) => return Err(Error::new_spanned(&ty, "Expect type").into()),
|
|
|
|
};
|
2020-03-06 15:58:43 +00:00
|
|
|
let mut calls = Vec::new();
|
|
|
|
let mut use_params = Vec::new();
|
|
|
|
let mut decl_params = Vec::new();
|
|
|
|
let mut get_params = Vec::new();
|
|
|
|
let mut schema_args = Vec::new();
|
2020-04-09 14:03:09 +00:00
|
|
|
let requires = match &requires {
|
2020-10-16 10:37:59 +00:00
|
|
|
Some(requires) => quote! { ::std::option::Option::Some(#requires) },
|
|
|
|
None => quote! { ::std::option::Option::None },
|
2020-04-09 14:03:09 +00:00
|
|
|
};
|
|
|
|
let provides = match &provides {
|
2020-10-16 10:37:59 +00:00
|
|
|
Some(provides) => quote! { ::std::option::Option::Some(#provides) },
|
|
|
|
None => quote! { ::std::option::Option::None },
|
2020-04-09 14:03:09 +00:00
|
|
|
};
|
2020-03-06 15:58:43 +00:00
|
|
|
|
2020-05-01 23:57:34 +00:00
|
|
|
decl_params.push(quote! { ctx: &'ctx #crate_name::Context<'ctx> });
|
|
|
|
use_params.push(quote! { ctx });
|
2020-03-07 03:21:56 +00:00
|
|
|
|
2022-05-07 08:16:01 +00:00
|
|
|
for InterfaceFieldArgument {
|
|
|
|
name,
|
|
|
|
desc,
|
|
|
|
ty,
|
|
|
|
default,
|
|
|
|
default_with,
|
|
|
|
visible,
|
|
|
|
secret,
|
|
|
|
} in args
|
|
|
|
{
|
2020-03-06 15:58:43 +00:00
|
|
|
let ident = Ident::new(name, Span::call_site());
|
2022-05-07 08:16:01 +00:00
|
|
|
let name = interface_args
|
|
|
|
.rename_args
|
|
|
|
.rename(name, RenameTarget::Argument);
|
2020-09-28 09:44:00 +00:00
|
|
|
let ty = match syn::parse_str::<syn::Type>(&ty.value()) {
|
|
|
|
Ok(ty) => ty,
|
|
|
|
Err(_) => return Err(Error::new_spanned(&ty, "Expect type").into()),
|
|
|
|
};
|
2020-03-06 15:58:43 +00:00
|
|
|
decl_params.push(quote! { #ident: #ty });
|
2020-03-07 03:21:56 +00:00
|
|
|
use_params.push(quote! { #ident });
|
2022-05-07 08:16:01 +00:00
|
|
|
|
|
|
|
let default = generate_default(default, default_with)?;
|
|
|
|
let get_default = match &default {
|
|
|
|
Some(default) => quote! { ::std::option::Option::Some(|| -> #ty { #default }) },
|
|
|
|
None => quote! { ::std::option::Option::None },
|
|
|
|
};
|
2020-03-06 15:58:43 +00:00
|
|
|
get_params.push(quote! {
|
2022-05-07 08:16:01 +00:00
|
|
|
let (_, #ident) = ctx.param_value::<#ty>(#name, #get_default)?;
|
2020-03-06 15:58:43 +00:00
|
|
|
});
|
2022-02-28 07:26:33 +00:00
|
|
|
|
2022-05-07 08:16:01 +00:00
|
|
|
let desc = desc
|
|
|
|
.as_ref()
|
|
|
|
.map(|s| quote! {::std::option::Option::Some(#s)})
|
|
|
|
.unwrap_or_else(|| quote! {::std::option::Option::None});
|
|
|
|
let schema_default = default
|
|
|
|
.as_ref()
|
|
|
|
.map(|value| {
|
|
|
|
quote! {
|
|
|
|
::std::option::Option::Some(::std::string::ToString::to_string(
|
|
|
|
&<#ty as #crate_name::InputType>::to_value(&#value)
|
|
|
|
))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_or_else(|| quote! {::std::option::Option::None});
|
|
|
|
let visible = visible_fn(visible);
|
|
|
|
schema_args.push(quote! {
|
2022-02-28 07:26:33 +00:00
|
|
|
args.insert(::std::borrow::ToOwned::to_owned(#name), #crate_name::registry::MetaInputValue {
|
|
|
|
name: #name,
|
|
|
|
description: #desc,
|
|
|
|
ty: <#ty as #crate_name::InputType>::create_type_info(registry),
|
|
|
|
default_value: #schema_default,
|
|
|
|
visible: #visible,
|
|
|
|
is_secret: #secret,
|
|
|
|
});
|
|
|
|
});
|
2020-03-06 15:58:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for enum_name in &enum_names {
|
|
|
|
calls.push(quote! {
|
2021-04-09 07:04:01 +00:00
|
|
|
#ident::#enum_name(obj) => obj.#method_name(#(#use_params),*)
|
|
|
|
.await.map_err(|err| ::std::convert::Into::<#crate_name::Error>::into(err))
|
|
|
|
.map(::std::convert::Into::into)
|
2020-03-06 15:58:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
let desc = desc
|
|
|
|
.as_ref()
|
2020-10-16 10:37:59 +00:00
|
|
|
.map(|s| quote! {::std::option::Option::Some(#s)})
|
|
|
|
.unwrap_or_else(|| quote! {::std::option::Option::None});
|
2021-02-27 03:59:58 +00:00
|
|
|
let deprecation = gen_deprecation(deprecation, &crate_name);
|
2020-03-06 15:58:43 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
let oty = OutputType::parse(&ty)?;
|
2020-05-01 23:57:34 +00:00
|
|
|
let ty = match oty {
|
|
|
|
OutputType::Value(ty) => ty,
|
|
|
|
OutputType::Result(_, ty) => ty,
|
|
|
|
};
|
|
|
|
let schema_ty = oty.value_type();
|
|
|
|
|
|
|
|
methods.push(quote! {
|
|
|
|
#[inline]
|
2020-10-24 01:08:18 +00:00
|
|
|
pub async fn #method_name<'ctx>(&self, #(#decl_params),*) -> #crate_name::Result<#ty> {
|
2020-05-01 23:57:34 +00:00
|
|
|
match self {
|
|
|
|
#(#calls,)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-03-06 15:58:43 +00:00
|
|
|
|
2021-07-31 15:54:16 +00:00
|
|
|
let visible = visible_fn(visible);
|
2020-03-06 15:58:43 +00:00
|
|
|
schema_fields.push(quote! {
|
2020-10-16 19:21:46 +00:00
|
|
|
fields.insert(::std::string::ToString::to_string(#name), #crate_name::registry::MetaField {
|
|
|
|
name: ::std::string::ToString::to_string(#name),
|
2020-03-06 15:58:43 +00:00
|
|
|
description: #desc,
|
2020-03-08 12:35:36 +00:00
|
|
|
args: {
|
2020-05-16 02:05:48 +00:00
|
|
|
let mut args = #crate_name::indexmap::IndexMap::new();
|
2020-03-08 12:35:36 +00:00
|
|
|
#(#schema_args)*
|
|
|
|
args
|
|
|
|
},
|
2021-11-09 10:52:10 +00:00
|
|
|
ty: <#schema_ty as #crate_name::OutputType>::create_type_info(registry),
|
2020-03-06 15:58:43 +00:00
|
|
|
deprecation: #deprecation,
|
2020-10-16 10:37:59 +00:00
|
|
|
cache_control: ::std::default::Default::default(),
|
2020-04-09 14:03:09 +00:00
|
|
|
external: #external,
|
|
|
|
provides: #provides,
|
|
|
|
requires: #requires,
|
2020-12-11 08:03:28 +00:00
|
|
|
visible: #visible,
|
2020-12-18 06:59:37 +00:00
|
|
|
compute_complexity: ::std::option::Option::None,
|
2020-03-08 12:35:36 +00:00
|
|
|
});
|
2020-03-06 15:58:43 +00:00
|
|
|
});
|
|
|
|
|
2020-05-01 23:57:34 +00:00
|
|
|
let resolve_obj = quote! {
|
2020-10-16 10:37:59 +00:00
|
|
|
self.#method_name(#(#use_params),*)
|
|
|
|
.await
|
2021-06-07 06:03:36 +00:00
|
|
|
.map_err(|err| ::std::convert::Into::<#crate_name::Error>::into(err).into_server_error(ctx.item.pos))?
|
2020-03-06 15:58:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
resolvers.push(quote! {
|
2020-09-12 16:42:15 +00:00
|
|
|
if ctx.item.node.name.node == #name {
|
2020-03-06 15:58:43 +00:00
|
|
|
#(#get_params)*
|
2020-09-12 16:42:15 +00:00
|
|
|
let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set);
|
2021-06-07 12:51:20 +00:00
|
|
|
return #crate_name::OutputType::resolve(&#resolve_obj, &ctx_obj, ctx.item).await.map(::std::option::Option::Some);
|
2020-03-06 15:58:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-20 06:37:28 +00:00
|
|
|
let introspection_type_name = if get_introspection_typename.is_empty() {
|
2020-10-16 10:37:59 +00:00
|
|
|
quote! { ::std::unreachable!() }
|
2020-04-20 06:37:28 +00:00
|
|
|
} else {
|
|
|
|
quote! {
|
|
|
|
match self {
|
|
|
|
#(#get_introspection_typename),*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-12-11 08:03:28 +00:00
|
|
|
let visible = visible_fn(&interface_args.visible);
|
2020-03-06 15:58:43 +00:00
|
|
|
let expanded = quote! {
|
|
|
|
#(#type_into_impls)*
|
|
|
|
|
2020-06-28 06:28:53 +00:00
|
|
|
#[allow(clippy::all, clippy::pedantic)]
|
2021-01-14 03:27:15 +00:00
|
|
|
impl #impl_generics #ident #ty_generics #where_clause {
|
2020-03-06 15:58:43 +00:00
|
|
|
#(#methods)*
|
|
|
|
}
|
|
|
|
|
2020-06-28 06:28:53 +00:00
|
|
|
#[allow(clippy::all, clippy::pedantic)]
|
2021-11-09 10:52:10 +00:00
|
|
|
#[#crate_name::async_trait::async_trait]
|
|
|
|
impl #impl_generics #crate_name::resolver_utils::ContainerType for #ident #ty_generics #where_clause {
|
|
|
|
async fn resolve_field(&self, ctx: &#crate_name::Context<'_>) -> #crate_name::ServerResult<::std::option::Option<#crate_name::Value>> {
|
|
|
|
#(#resolvers)*
|
|
|
|
::std::result::Result::Ok(::std::option::Option::None)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn collect_all_fields<'__life>(&'__life self, ctx: &#crate_name::ContextSelectionSet<'__life>, fields: &mut #crate_name::resolver_utils::Fields<'__life>) -> #crate_name::ServerResult<()> {
|
|
|
|
match self {
|
|
|
|
#(#collect_all_fields),*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(clippy::all, clippy::pedantic)]
|
|
|
|
#[#crate_name::async_trait::async_trait]
|
|
|
|
impl #impl_generics #crate_name::OutputType for #ident #ty_generics #where_clause {
|
2020-10-16 10:37:59 +00:00
|
|
|
fn type_name() -> ::std::borrow::Cow<'static, ::std::primitive::str> {
|
2020-06-24 06:04:48 +00:00
|
|
|
::std::borrow::Cow::Borrowed(#gql_typename)
|
2020-03-06 15:58:43 +00:00
|
|
|
}
|
|
|
|
|
2020-10-16 10:37:59 +00:00
|
|
|
fn introspection_type_name(&self) -> ::std::borrow::Cow<'static, ::std::primitive::str> {
|
2020-04-20 06:37:28 +00:00
|
|
|
#introspection_type_name
|
2020-04-02 12:37:01 +00:00
|
|
|
}
|
|
|
|
|
2020-10-16 10:37:59 +00:00
|
|
|
fn create_type_info(registry: &mut #crate_name::registry::Registry) -> ::std::string::String {
|
2022-03-30 12:54:49 +00:00
|
|
|
registry.create_output_type::<Self, _>(#crate_name::registry::MetaTypeId::Interface, |registry| {
|
2020-03-06 15:58:43 +00:00
|
|
|
#(#registry_types)*
|
|
|
|
|
2020-05-15 02:08:37 +00:00
|
|
|
#crate_name::registry::MetaType::Interface {
|
2020-10-16 19:21:46 +00:00
|
|
|
name: ::std::string::ToString::to_string(#gql_typename),
|
2020-03-06 15:58:43 +00:00
|
|
|
description: #desc,
|
2020-03-08 12:35:36 +00:00
|
|
|
fields: {
|
2020-05-16 02:05:48 +00:00
|
|
|
let mut fields = #crate_name::indexmap::IndexMap::new();
|
2020-03-08 12:35:36 +00:00
|
|
|
#(#schema_fields)*
|
|
|
|
fields
|
|
|
|
},
|
2020-03-10 10:07:47 +00:00
|
|
|
possible_types: {
|
2020-05-16 02:05:48 +00:00
|
|
|
let mut possible_types = #crate_name::indexmap::IndexSet::new();
|
2020-03-10 10:07:47 +00:00
|
|
|
#(#possible_types)*
|
|
|
|
possible_types
|
|
|
|
},
|
2020-04-09 14:03:09 +00:00
|
|
|
extends: #extends,
|
2020-10-16 10:37:59 +00:00
|
|
|
keys: ::std::option::Option::None,
|
2020-12-11 08:03:28 +00:00
|
|
|
visible: #visible,
|
2021-11-08 01:33:20 +00:00
|
|
|
rust_typename: ::std::any::type_name::<Self>(),
|
2020-03-06 15:58:43 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-03-19 09:20:12 +00:00
|
|
|
|
2021-06-07 12:51:20 +00:00
|
|
|
async fn resolve(
|
|
|
|
&self,
|
|
|
|
ctx: &#crate_name::ContextSelectionSet<'_>,
|
|
|
|
_field: &#crate_name::Positioned<#crate_name::parser::types::Field>,
|
|
|
|
) -> #crate_name::ServerResult<#crate_name::Value> {
|
2020-09-29 23:45:48 +00:00
|
|
|
#crate_name::resolver_utils::resolve_container(ctx, self).await
|
2020-03-19 09:20:12 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-27 07:32:55 +00:00
|
|
|
|
2021-01-14 03:27:15 +00:00
|
|
|
impl #impl_generics #crate_name::InterfaceType for #ident #ty_generics #where_clause {}
|
2020-03-06 15:58:43 +00:00
|
|
|
};
|
|
|
|
Ok(expanded.into())
|
|
|
|
}
|