From 4432548fdbe6077c514056d7cf3c7372b2f1a628 Mon Sep 17 00:00:00 2001 From: Panagiotis Karatakis Date: Sun, 16 Oct 2022 23:28:11 +0300 Subject: [PATCH] Add config handover to queries --- derive/src/root_query.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/derive/src/root_query.rs b/derive/src/root_query.rs index dc6cc5fb..59ad1419 100644 --- a/derive/src/root_query.rs +++ b/derive/src/root_query.rs @@ -19,16 +19,26 @@ pub fn root_query_fn( _ => false } }) - .map(|attribute| -> Result { - if let syn::Lit::Str(item) = attribute.entity.as_ref().unwrap() { + .map(|attribute| -> Result<(TokenStream, TokenStream), crate::error::Error> { + let entity_name = if let syn::Lit::Str(item) = attribute.entity.as_ref().unwrap() { Ok(item.value().parse::()?) } else { Err(crate::error::Error::Internal( "Unreachable parse of query entities".into(), )) - } + }?; + + let config = if let Some(config) = &attribute.object_config { + quote!{ + #[graphql(#config)] + } + } else { + quote!{} + }; + + Ok((entity_name, config)) }) - .collect::, crate::error::Error>>()?; + .collect::, crate::error::Error>>()?; let object_config = attrs .iter() @@ -55,12 +65,13 @@ pub fn root_query_fn( let queries: Vec = paths .iter() - .map(|path| { + .map(|(path, config)| { let name = format_ident!("{}", path.clone().into_iter().last().unwrap().to_string()); let basic_query = basic_query(&name, path); quote! { + #config #basic_query } })