Skip to content

Commit 7c626da

Browse files
committed
Support Paths in response derives.
Up until now only Idents were supported in the response_derives section, which unfortunately wouldn't allow us to provide fully qualified names. This commit enables Path support, and provides us with an error message if we couldn't parse a response_derive as a valid Path.
1 parent a781420 commit 7c626da

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

graphql_client/tests/more_derives.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use graphql_client::*;
44
#[graphql(
55
schema_path = "tests/more_derives/schema.graphql",
66
query_path = "tests/more_derives/query.graphql",
7-
response_derives = "Debug, PartialEq, PartialOrd"
7+
response_derives = "Debug, PartialEq, std::cmp::PartialOrd"
88
)]
99
pub struct MoreDerives;
1010

graphql_client_codegen/src/codegen.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ fn generate_scalar_definitions<'a, 'schema: 'a>(
165165
}
166166

167167
fn render_derives<'a>(derives: impl Iterator<Item = &'a str>) -> impl quote::ToTokens {
168-
let idents = derives.map(|s| Ident::new(s, Span::call_site()));
168+
let idents = derives.map(|s| {
169+
syn::parse_str::<syn::Path>(s)
170+
.expect(format!("couldn't parse {} as a derive Path", s).as_str())
171+
});
169172

170173
quote!(#[derive(#(#idents),*)])
171174
}

0 commit comments

Comments
 (0)