Skip to content

Commit 10f6ce7

Browse files
committed
Add changelog entry for the new Rust keywords handling
1 parent e837d83 commit 10f6ce7

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3838

3939
- The CLI now supports the `--authorization` flag to pass the contents of an `Authorization` header. Thanks to @h-michael for the [PR](https://github.com/tomhoule/graphql-client/pull/92)!
4040

41+
### Fixed
42+
43+
- Handle all Rust keywords as field names in codegen by appending `_` to the generated names, so a field called `type` in a GraphQL query will become a `type_` field in the generated struct. Thanks to @scrogson!
44+
4145
## [0.4.0] - 2018-08-23
4246

4347
There are a number of breaking changes due to the new features, read the `Added` section attentively if you are upgrading.

graphql_query_derive/src/shared.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub(crate) fn render_object_field(
3535

3636
let description = description.map(|s| quote!(#[doc = #s]));
3737

38+
// List of keywords based on https://doc.rust-lang.org/grammar.html#keywords
3839
let reserved = &[
3940
"abstract", "alignof", "as", "become", "box", "break", "const", "continue", "crate", "do",
4041
"else", "enum", "extern", "false", "final", "fn", "for", "if", "impl", "in", "let", "loop",
@@ -86,7 +87,8 @@ pub(crate) fn field_impls_for_selection(
8687
} else {
8788
Ok(quote!())
8889
}
89-
}).collect()
90+
})
91+
.collect()
9092
}
9193

9294
pub(crate) fn response_fields_for_selection(
@@ -131,12 +133,14 @@ pub(crate) fn response_fields_for_selection(
131133
SelectionItem::InlineFragment(_) => {
132134
Err(format_err!("inline fragment on object field"))?
133135
}
134-
}).filter(|x| match x {
136+
})
137+
.filter(|x| match x {
135138
// Remove empty fields so callers always know a field has some
136139
// tokens.
137140
Ok(f) => !f.is_empty(),
138141
Err(_) => true,
139-
}).collect()
142+
})
143+
.collect()
140144
}
141145

142146
/// Given the GraphQL schema name for an object/interface/input object field and

0 commit comments

Comments
 (0)