Skip to content

Commit 86ba87b

Browse files
committed
Make object fields snake case
To align with convention.
1 parent 65ee00b commit 86ba87b

File tree

12 files changed

+19
-16
lines changed

12 files changed

+19
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This library does not provide any networking, caching or other client functional
66

77
```rust
88
#[derive(GraphQLQuery)]
9-
#[GraphQLQuery(
9+
#[gql(
1010
query = "/graphql/queries/my_query.graphql",
1111
schema = "/graphql/schema.graphql"
1212
)]

examples/call_from_js/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ fn cb() -> Closure<Fn(String)> {
106106
.expect("reddit")
107107
.subreddit
108108
.expect("puppy smiles subreddit")
109-
.newListings;
109+
.new_listings;
110110

111111
let new_cursor: Option<String> = listings[listings.len() - 1]
112112
.as_ref()
113-
.map(|puppy| puppy.fullnameId.clone())
113+
.map(|puppy| puppy.fullname_id.clone())
114114
.to_owned();
115115
LAST_ENTRY.lock().unwrap().replace(new_cursor);
116116

examples/github/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern crate serde_derive;
1010
use graphql_client::*;
1111

1212
#[derive(GraphQLQuery)]
13-
#[GraphQLQuery(schema_path = "src/schema.graphql", query_path = "src/query_1.graphql")]
13+
#[gql(schema_path = "src/schema.graphql", query_path = "src/query_1.graphql")]
1414
struct Query1;
1515

1616
fn main() -> Result<(), failure::Error> {

graphql_client_cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::path::PathBuf;
1313
use structopt::StructOpt;
1414

1515
#[derive(GraphQLQuery)]
16-
#[GraphQLQuery(
16+
#[gql(
1717
schema_path = "src/introspection_schema.graphql", query_path = "src/introspection_query.graphql"
1818
)]
1919
struct IntrospectionQuery;

graphql_query_derive/src/objects.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ impl GqlObject {
6464
#(#field_impls)*
6565

6666
#[derive(Debug, Serialize, Deserialize)]
67+
#[serde(rename_all = "camelCase")]
6768
pub struct #name {
6869
#(#fields,)*
6970
}

graphql_query_derive/src/shared.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(crate) fn render_object_field(field_name: &str, field_type: &TokenStream) ->
1414
};
1515
}
1616

17-
let name_ident = Ident::new(field_name, Span::call_site());
17+
let name_ident = Ident::new(&field_name.to_snake_case(), Span::call_site());
1818

1919
quote!(pub #name_ident: #field_type)
2020
}

graphql_query_derive/src/unions.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,10 @@ mod tests {
295295
result.unwrap().to_string(),
296296
vec![
297297
"# [ derive ( Debug , Serialize , Deserialize ) ] ",
298+
"# [ serde ( rename_all = \"camelCase\" ) ] ",
298299
"pub struct MeowOnUser { pub first_name : String , } ",
299300
"# [ derive ( Debug , Serialize , Deserialize ) ] ",
301+
"# [ serde ( rename_all = \"camelCase\" ) ] ",
300302
"pub struct MeowOnOrganization { pub title : String , } ",
301303
"# [ derive ( Debug , Serialize , Deserialize ) ] ",
302304
"# [ serde ( tag = \"__typename\" ) ] ",

tests/input_object_variables.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ extern crate serde;
66
extern crate serde_json;
77

88
#[derive(GraphQLQuery)]
9-
#[GraphQLQuery(
9+
#[gql(
1010
query_path = "tests/input_object_variables/input_object_variables_query.graphql",
1111
schema_path = "tests/input_object_variables/input_object_variables_schema.graphql"
1212
)]
@@ -28,7 +28,7 @@ fn input_object_variables_query_variables_struct() {
2828
}
2929

3030
#[derive(GraphQLQuery)]
31-
#[GraphQLQuery(
31+
#[gql(
3232
query_path = "tests/input_object_variables/input_object_variables_query_defaults.graphql",
3333
schema_path = "tests/input_object_variables/input_object_variables_schema.graphql"
3434
)]

tests/interfaces.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extern crate serde_json;
88
const RESPONSE: &'static str = include_str!("interfaces/interface_response.json");
99

1010
#[derive(GraphQLQuery)]
11-
#[GraphQLQuery(
11+
#[gql(
1212
query_path = "tests/interfaces/interface_query.graphql",
1313
schema_path = "tests/interfaces/interface_schema.graphql"
1414
)]
@@ -22,15 +22,15 @@ fn interface_deserialization() {
2222

2323
println!("{:?}", response_data);
2424

25-
let expected = r##"ResponseData { everything: Some([RustMyQueryEverything { name: "Audrey Lorde", on: Person(RustMyQueryEverythingOnPerson { birthday: Some("1934-02-18") }) }, RustMyQueryEverything { name: "Laïka", on: Dog(RustMyQueryEverythingOnDog { isGoodDog: true }) }, RustMyQueryEverything { name: "Mozilla", on: Organization(RustMyQueryEverythingOnOrganization { industry: OTHER }) }, RustMyQueryEverything { name: "Norbert", on: Dog(RustMyQueryEverythingOnDog { isGoodDog: true }) }]) }"##;
25+
let expected = r##"ResponseData { everything: Some([RustMyQueryEverything { name: "Audrey Lorde", on: Person(RustMyQueryEverythingOnPerson { birthday: Some("1934-02-18") }) }, RustMyQueryEverything { name: "Laïka", on: Dog(RustMyQueryEverythingOnDog { is_good_dog: true }) }, RustMyQueryEverything { name: "Mozilla", on: Organization(RustMyQueryEverythingOnOrganization { industry: OTHER }) }, RustMyQueryEverything { name: "Norbert", on: Dog(RustMyQueryEverythingOnDog { is_good_dog: true }) }]) }"##;
2626

2727
assert_eq!(format!("{:?}", response_data), expected);
2828

2929
assert_eq!(response_data.everything.map(|names| names.len()), Some(4));
3030
}
3131

3232
#[derive(GraphQLQuery)]
33-
#[GraphQLQuery(
33+
#[gql(
3434
query_path = "tests/interfaces/interface_not_on_everything_query.graphql",
3535
schema_path = "tests/interfaces/interface_schema.graphql"
3636
)]

tests/introspection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate serde_derive;
55
extern crate serde;
66

77
#[derive(GraphQLQuery)]
8-
#[GraphQLQuery(
8+
#[gql(
99
query_path = "tests/introspection/introspection_query.graphql",
1010
schema_path = "tests/introspection/introspection_schema.graphql"
1111
)]

0 commit comments

Comments
 (0)