1- #![ recursion_limit = "128 " ]
1+ #![ recursion_limit = "512 " ]
22
33#[ macro_use]
44extern crate failure;
@@ -16,6 +16,7 @@ extern crate quote;
1616
1717use proc_macro2:: TokenStream ;
1818
19+ mod attributes;
1920mod codegen;
2021mod constants;
2122mod enums;
@@ -77,8 +78,9 @@ fn impl_gql_query(input: &syn::DeriveInput) -> Result<TokenStream, failure::Erro
7778 let cargo_manifest_dir =
7879 :: std:: env:: var ( "CARGO_MANIFEST_DIR" ) . expect ( "CARGO_MANIFEST_DIR env variable is defined" ) ;
7980
80- let query_path = extract_attr ( input, "query_path" ) ?;
81- let schema_path = extract_attr ( input, "schema_path" ) ?;
81+ let query_path = attributes:: extract_attr ( input, "query_path" ) ?;
82+ let schema_path = attributes:: extract_attr ( input, "schema_path" ) ?;
83+ let response_derives = attributes:: extract_attr ( input, "response_derives" ) . ok ( ) ;
8284
8385 // We need to qualify the query with the path to the crate it is part of
8486 let query_path = format ! ( "{}/{}" , cargo_manifest_dir, query_path) ;
@@ -108,7 +110,8 @@ fn impl_gql_query(input: &syn::DeriveInput) -> Result<TokenStream, failure::Erro
108110
109111 let module_name = Ident :: new ( & input. ident . to_string ( ) . to_snake_case ( ) , Span :: call_site ( ) ) ;
110112 let struct_name = & input. ident ;
111- let schema_output = codegen:: response_for_query ( schema, query, input. ident . to_string ( ) ) ?;
113+ let schema_output =
114+ codegen:: response_for_query ( schema, query, input. ident . to_string ( ) , response_derives) ?;
112115
113116 let result = quote ! (
114117 pub mod #module_name {
@@ -139,30 +142,3 @@ fn impl_gql_query(input: &syn::DeriveInput) -> Result<TokenStream, failure::Erro
139142
140143 Ok ( result)
141144}
142-
143- fn extract_attr ( ast : & syn:: DeriveInput , attr : & str ) -> Result < String , failure:: Error > {
144- let attributes = & ast. attrs ;
145- let attribute = attributes
146- . iter ( )
147- . find ( |attr| {
148- let path = & attr. path ;
149- quote ! ( #path) . to_string ( ) == "graphql"
150- } ) . ok_or_else ( || format_err ! ( "The graphql attribute is missing" ) ) ?;
151- if let syn:: Meta :: List ( items) = & attribute
152- . interpret_meta ( )
153- . expect ( "Attribute is well formatted" )
154- {
155- for item in items. nested . iter ( ) {
156- if let syn:: NestedMeta :: Meta ( syn:: Meta :: NameValue ( name_value) ) = item {
157- let syn:: MetaNameValue { ident, lit, .. } = name_value;
158- if ident == attr {
159- if let syn:: Lit :: Str ( lit) = lit {
160- return Ok ( lit. value ( ) ) ;
161- }
162- }
163- }
164- }
165- }
166-
167- Err ( format_err ! ( "attribute not found" ) ) ?
168- }
0 commit comments