Skip to content

Commit

Permalink
Add config handover to queries
Browse files Browse the repository at this point in the history
  • Loading branch information
karatakis committed Oct 16, 2022
1 parent 8582a1e commit 4432548
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions derive/src/root_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,26 @@ pub fn root_query_fn(
_ => false
}
})
.map(|attribute| -> Result<TokenStream, crate::error::Error> {
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::<TokenStream>()?)
} 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::<Result<Vec<TokenStream>, crate::error::Error>>()?;
.collect::<Result<Vec<(TokenStream, TokenStream)>, crate::error::Error>>()?;

let object_config = attrs
.iter()
Expand All @@ -55,12 +65,13 @@ pub fn root_query_fn(

let queries: Vec<TokenStream> = 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
}
})
Expand Down

0 comments on commit 4432548

Please sign in to comment.