diff --git a/derive/src/root_query.rs b/derive/src/root_query.rs index 21fd555e..dc6cc5fb 100644 --- a/derive/src/root_query.rs +++ b/derive/src/root_query.rs @@ -1,9 +1,10 @@ use proc_macro2::{Ident, TokenStream}; use quote::{format_ident, quote}; -#[derive(Debug, Eq, PartialEq, bae::FromAttributes)] +#[derive(Debug, Eq, PartialEq, bae::FromAttributes, Clone)] pub struct Seaography { - entity: syn::Lit, + entity: Option, + object_config: Option } pub fn root_query_fn( @@ -12,8 +13,14 @@ pub fn root_query_fn( ) -> Result { let paths = attrs .iter() + .filter(|attribute| { + match &attribute.entity { + Some(_) => true, + _ => false + } + }) .map(|attribute| -> Result { - if let syn::Lit::Str(item) = &attribute.entity { + if let syn::Lit::Str(item) = attribute.entity.as_ref().unwrap() { Ok(item.value().parse::()?) } else { Err(crate::error::Error::Internal( @@ -23,6 +30,29 @@ pub fn root_query_fn( }) .collect::, crate::error::Error>>()?; + let object_config = attrs + .iter() + .find(|attribute| { + match attribute.object_config { + Some(_) => true, + _ => false + } + }) + .map(|attribute| attribute.object_config.as_ref().unwrap()); + + let implement_macros = match object_config { + Some(object_config) => { + quote! { + #[async_graphql::Object(#object_config)] + } + }, + _ => { + quote! { + #[async_graphql::Object] + } + } + }; + let queries: Vec = paths .iter() .map(|path| { @@ -41,7 +71,7 @@ pub fn root_query_fn( Ok(quote! { #basic_dependencies - #[async_graphql::Object] + #implement_macros impl #ident { #(#queries)* } @@ -255,7 +285,6 @@ pub fn basic_dependencies() -> TokenStream { Cursor(CursorInput), } - #[derive(async_graphql::SimpleObject)] pub struct ExtraPaginationFields { pub pages: Option,