Skip to content

Commit 8be8a8f

Browse files
committed
use pascal for module names
1 parent 29f4159 commit 8be8a8f

File tree

6 files changed

+24
-14
lines changed

6 files changed

+24
-14
lines changed

src/build_schema.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use cynic_introspection::{
1010
Directive, DirectiveLocation, FieldWrapping, InputValue, InterfaceType, IntrospectionQuery,
1111
Type, UnionType, WrappingType,
1212
};
13-
use stringcase::{kebab_case, pascal_case};
13+
use stringcase::{kebab_case};
1414
use tokio::task::spawn_blocking;
1515

1616
use crate::{
@@ -26,6 +26,7 @@ use crate::{
2626
purescript_record::{show_field_name, Field, PurescriptRecord},
2727
purescript_type::PurescriptType,
2828
purescript_variant::Variant,
29+
upper_first::*,
2930
},
3031
write::write,
3132
};
@@ -98,7 +99,7 @@ pub async fn build_schema(
9899
let query_type = PurescriptType::new(
99100
"Query",
100101
vec![],
101-
Argument::new_type(&pascal_case(schema.query_type.as_str())),
102+
Argument::new_type(&upper_first(schema.query_type.as_str())),
102103
);
103104
schema_record.add_field(Field::new("query").with_type(&query_type.name));
104105
types.push(query_type);
@@ -113,7 +114,7 @@ pub async fn build_schema(
113114
let mutation_type = PurescriptType::new(
114115
"Mutation",
115116
vec![],
116-
Argument::new_type(&pascal_case(&mut_type)),
117+
Argument::new_type(&upper_first(&mut_type)),
117118
);
118119
schema_record.add_field(Field::new("mutation").with_type(&mutation_type.name));
119120
types.push(mutation_type);
@@ -124,7 +125,7 @@ pub async fn build_schema(
124125
let mutation_type = PurescriptType::new(
125126
"Subscription",
126127
vec![],
127-
Argument::new_type(&pascal_case(&mut_type)),
128+
Argument::new_type(&upper_first(&mut_type)),
128129
);
129130
schema_record.add_field(Field::new("subscription").with_type(&mutation_type.name));
130131
types.push(mutation_type);
@@ -139,7 +140,7 @@ pub async fn build_schema(
139140
}
140141

141142
// Convert the gql_type_name to a PurescriptTypeName
142-
let name = pascal_case(&obj.name);
143+
let name = upper_first(&obj.name);
143144

144145
// Creates a new record for the object
145146
let mut record = PurescriptRecord::new("Ignored");
@@ -214,6 +215,7 @@ pub async fn build_schema(
214215
add_import("argonaut-core", "Data.Argonaut.Core", "Json", &mut imports)
215216
}
216217
"time" => add_import("datetime", "Data.Time", "Time", &mut imports),
218+
"ID" => add_import("graphql-client", "GraphQL.Client.ID", "ID", &mut imports),
217219
_ => {}
218220
}
219221
}
@@ -239,7 +241,7 @@ pub async fn build_schema(
239241
}
240242

241243
// Convert the gql_type_name to a PurescriptTypeName
242-
let name = pascal_case(&obj.name);
244+
let name = upper_first(&obj.name);
243245

244246
// Build a purescript record with all fields
245247
let mut record = PurescriptRecord::new("Query");
@@ -302,7 +304,7 @@ pub async fn build_schema(
302304
union.with_values(
303305
&possible_types
304306
.iter()
305-
.map(|t| (t.clone(), pascal_case(&t)))
307+
.map(|t| (t.clone(), upper_first(&t)))
306308
.collect(),
307309
);
308310

src/config/parse_outside_types.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ use std::{
44
io::Read,
55
};
66

7-
use stringcase::pascal_case;
87
use yaml_rust2::{yaml, Yaml};
98

10-
use crate::write::write;
9+
use crate::{purescript_gen::upper_first::upper_first, write::write};
1110

1211
use super::workspace::WorkspaceConfig;
1312

@@ -218,8 +217,8 @@ fn write_types(outside_types: &OutsideTypes, workspace_config: &WorkspaceConfig)
218217
let mock_outside_types = std::env::var("MOCK_OUTSIDE_TYPES");
219218
if mock_outside_types.is_ok() {
220219
let lib_path = workspace_config.shared_graphql_enums_dir.clone();
221-
let postgres_enums_lib = pascal_case(&(&workspace_config.postgres_enums_lib).clone().unwrap());
222-
let gql_enums_lib = pascal_case(&workspace_config.shared_graphql_enums_lib);
220+
let postgres_enums_lib = upper_first(&(&workspace_config.postgres_enums_lib).clone().unwrap());
221+
let gql_enums_lib = upper_first(&workspace_config.shared_graphql_enums_lib);
223222
for module in to_write.iter() {
224223
let is_enum_mod = module.import.contains(&postgres_enums_lib)
225224
|| module.import.contains(&gql_enums_lib);

src/enums/generate_enum.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::config::workspace::WorkspaceConfig;
55
use crate::purescript_gen::purescript_enum::Enum;
66
use crate::purescript_gen::purescript_import::PurescriptImport;
77
use crate::purescript_gen::purescript_variant::Variant;
8+
use crate::purescript_gen::upper_first::upper_first;
89
use crate::write::write;
910

1011
pub async fn generate_enum(

src/hasura_types.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ use std::{
22
collections::HashMap,
33
sync::{Arc, Mutex},
44
};
5-
use stringcase::pascal_case;
65

76
use crate::{
87
config::parse_outside_types::{Mod, OutsideTypes},
9-
purescript_gen::{purescript_argument::Argument, purescript_import::PurescriptImport},
8+
purescript_gen::{purescript_argument::Argument, purescript_import::PurescriptImport, upper_first::upper_first},
109
};
1110

1211
pub fn as_gql_field(
@@ -26,7 +25,7 @@ pub fn as_gql_field(
2625
}
2726
Argument::new_type("AsGql")
2827
.with_argument(Argument::new_type(&format!("\"{}\"", name)))
29-
.with_argument(Argument::new_type(&pascal_case(&type_)))
28+
.with_argument(Argument::new_type(&upper_first(&type_)))
3029
}
3130

3231
fn outside_type(

src/purescript_gen.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ pub mod purescript_type;
88
pub mod purescript_variant;
99
pub mod purescript_row;
1010
pub mod purescript_gql_union;
11+
pub mod upper_first;

src/purescript_gen/upper_first.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
pub fn upper_first(str: &str) -> String {
3+
let mut c = str.chars();
4+
match c.next() {
5+
None => String::new(),
6+
Some(f) => f.to_uppercase().collect::<String>() + c.as_str(),
7+
}
8+
}

0 commit comments

Comments
 (0)