Make GraphQL interface value enum variants named after the type they contain
This commit is contained in:
parent
4dbd740fef
commit
bcbf44ecbd
1 changed files with 20 additions and 16 deletions
|
@ -1641,11 +1641,15 @@ impl EnumType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns name of a single variant of this [`EnumType`] by the given positional `num` in the
|
/// Returns name of a single variant of this [`EnumType`] by the given underlying [`syn::Type`]
|
||||||
/// enum type definition.
|
/// of the variant.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn variant_ident(num: usize) -> syn::Ident {
|
fn variant_ident(ty: &syn::Type) -> &syn::Ident {
|
||||||
format_ident!("Impl{}", num)
|
if let syn::Type::Path(p) = ty {
|
||||||
|
&p.path.segments.last().unwrap().ident
|
||||||
|
} else {
|
||||||
|
unreachable!("GraphQL object has unexpected type `{}`", quote! { #ty })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Indicates whether this [`EnumType`] has non-exhaustive phantom variant to hold type
|
/// Indicates whether this [`EnumType`] has non-exhaustive phantom variant to hold type
|
||||||
|
@ -1728,8 +1732,8 @@ impl EnumType {
|
||||||
self.trait_ident,
|
self.trait_ident,
|
||||||
);
|
);
|
||||||
|
|
||||||
let variants = self.variants.iter().enumerate().map(|(n, ty)| {
|
let variants = self.variants.iter().map(|ty| {
|
||||||
let variant = Self::variant_ident(n);
|
let variant = Self::variant_ident(ty);
|
||||||
let doc = format!(
|
let doc = format!(
|
||||||
"`{}` implementer of this GraphQL interface.",
|
"`{}` implementer of this GraphQL interface.",
|
||||||
quote! { #ty },
|
quote! { #ty },
|
||||||
|
@ -1783,8 +1787,8 @@ impl EnumType {
|
||||||
let enum_ty = &self.ident;
|
let enum_ty = &self.ident;
|
||||||
let (impl_generics, generics, where_clause) = self.trait_generics.split_for_impl();
|
let (impl_generics, generics, where_clause) = self.trait_generics.split_for_impl();
|
||||||
|
|
||||||
self.variants.iter().enumerate().map(move |(n, ty)| {
|
self.variants.iter().map(move |ty| {
|
||||||
let variant = Self::variant_ident(n);
|
let variant = Self::variant_ident(ty);
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
#[automatically_derived]
|
#[automatically_derived]
|
||||||
|
@ -1846,8 +1850,8 @@ impl EnumType {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let match_arms = self.variants.iter().enumerate().map(|(n, ty)| {
|
let match_arms = self.variants.iter().map(|ty| {
|
||||||
let variant = Self::variant_ident(n);
|
let variant = Self::variant_ident(ty);
|
||||||
let args = args.clone();
|
let args = args.clone();
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
|
@ -1905,8 +1909,8 @@ impl EnumType {
|
||||||
fn method_concrete_type_name_tokens(&self) -> TokenStream {
|
fn method_concrete_type_name_tokens(&self) -> TokenStream {
|
||||||
let scalar = &self.scalar;
|
let scalar = &self.scalar;
|
||||||
|
|
||||||
let match_arms = self.variants.iter().enumerate().map(|(n, ty)| {
|
let match_arms = self.variants.iter().map(|ty| {
|
||||||
let variant = Self::variant_ident(n);
|
let variant = Self::variant_ident(ty);
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
Self::#variant(v) => <
|
Self::#variant(v) => <
|
||||||
|
@ -1932,8 +1936,8 @@ impl EnumType {
|
||||||
fn method_resolve_into_type_tokens(&self) -> TokenStream {
|
fn method_resolve_into_type_tokens(&self) -> TokenStream {
|
||||||
let resolving_code = gen::sync_resolving_code();
|
let resolving_code = gen::sync_resolving_code();
|
||||||
|
|
||||||
let match_arms = self.variants.iter().enumerate().map(|(n, _)| {
|
let match_arms = self.variants.iter().map(|ty| {
|
||||||
let variant = Self::variant_ident(n);
|
let variant = Self::variant_ident(ty);
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
Self::#variant(res) => #resolving_code,
|
Self::#variant(res) => #resolving_code,
|
||||||
|
@ -1957,8 +1961,8 @@ impl EnumType {
|
||||||
fn method_resolve_into_type_async_tokens(&self) -> TokenStream {
|
fn method_resolve_into_type_async_tokens(&self) -> TokenStream {
|
||||||
let resolving_code = gen::async_resolving_code(None);
|
let resolving_code = gen::async_resolving_code(None);
|
||||||
|
|
||||||
let match_arms = self.variants.iter().enumerate().map(|(n, _)| {
|
let match_arms = self.variants.iter().map(|ty| {
|
||||||
let variant = Self::variant_ident(n);
|
let variant = Self::variant_ident(ty);
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
Self::#variant(v) => {
|
Self::#variant(v) => {
|
||||||
|
|
Loading…
Reference in a new issue