Skip to content

Commit 655361f

Browse files
committed
Base object prefixes on path instead of type_
This would have been a problem if two fields in the same object had the same return type.
1 parent 77e640e commit 655361f

File tree

4 files changed

+5
-12
lines changed

4 files changed

+5
-12
lines changed

graphql_query_derive/src/field_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl FieldType {
1313
pub fn to_rust(&self, context: &QueryContext, prefix: &str) -> TokenStream {
1414
match &self {
1515
FieldType::Named(name) => {
16-
let name = Ident::new(&format!("{}{}", prefix, name), Span::call_site());
16+
let name = Ident::new(prefix, Span::call_site());
1717
quote!(#name)
1818
}
1919
FieldType::Optional(inner) => {

graphql_query_derive/src/interfaces.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl GqlInterface {
1818
selection: &query::SelectionSet,
1919
prefix: &str,
2020
) -> TokenStream {
21-
let name = Ident::new(&format!("{}{}", prefix, self.name), Span::call_site());
21+
let name = Ident::new(&prefix, Span::call_site());
2222
quote! {
2323
#[derive(Debug, Deserialize)]
2424
pub struct #name;

graphql_query_derive/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ use heck::*;
2727
use proc_macro2::{Ident, Span};
2828
use schema::Schema;
2929

30-
struct DeriveContext {
31-
schema: Schema,
32-
structs: BTreeMap<String, TokenStream>,
33-
enums: BTreeMap<String, TokenStream>,
34-
inputs: BTreeMap<String, TokenStream>,
35-
}
36-
3730
#[proc_macro_derive(GraphQLQuery, attributes(GraphQLQuery))]
3831
pub fn graphql_query_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
3932
let input = TokenStream::from(input);

graphql_query_derive/src/objects.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ impl GqlObject {
2323
selection: &query::SelectionSet,
2424
prefix: &str,
2525
) -> TokenStream {
26-
let name = Ident::new(&format!("{}{}", prefix, self.name), Span::call_site());
26+
let name = Ident::new(prefix, Span::call_site());
2727
let fields = self.response_fields_for_selection(query_context, selection, prefix);
28-
let prefix = format!("{}{}", prefix, self.name);
2928
let field_impls = self.field_impls_for_selection(query_context, selection, &prefix);
3029
quote! {
3130
#(#field_impls)*
@@ -55,6 +54,7 @@ impl GqlObject {
5554
.expect("field found")
5655
.type_
5756
.inner_name_string();
57+
let prefix = format!("{}{}", prefix, selected.name);
5858
query_context.maybe_expand_field(&selected, &ty, &prefix)
5959
} else {
6060
quote!()
@@ -82,7 +82,7 @@ impl GqlObject {
8282
.unwrap()
8383
.type_;
8484
let name = Ident::new(name, Span::call_site());
85-
let ty = ty.to_rust(query_context, prefix);
85+
let ty = ty.to_rust(query_context, &format!("{}{}", prefix, name));
8686
fields.push(quote!(#name: #ty));
8787
}
8888
query::Selection::FragmentSpread(fragment) => {

0 commit comments

Comments
 (0)