Skip to content

Commit

Permalink
Fixed Some Runtime Issues
Browse files Browse the repository at this point in the history
When running the tool with no config specified, the std default derive would not use serde defaults.
This has been alleviated by implementing Default manually.

In Schema mode, when files are not produced, like input_objects.rs, the mod.rs still included them in the imports.
As far as I can tell, the code is already prepared to return false when this happens, so I just removed the hardcoded true that was there, as that would override the file creation bool as true regardless of what the function reported.

Finally, I updated all the dependencies in the main project. I didn't get around to updating the dependencies in the examples however.
  • Loading branch information
dasanibroto committed Jul 29, 2024
1 parent 4f07d89 commit 8542847
Show file tree
Hide file tree
Showing 8 changed files with 674 additions and 633 deletions.
1,224 changes: 623 additions & 601 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,28 @@ path = "src/bin/main.rs"

[dependencies]
anyhow = "1.0"
async-graphql = "6.0.1"
async-graphql-parser = "6.0.1"
clap = { version = "3.1.0", features = ["derive"] }
env_logger = "0.8"
async-graphql = "7.0.7"
async-graphql-parser = "7.0.7"
clap = { version = "4.5.11", features = ["derive"] }
env_logger = "0.11.5"
# TODO(tacogips) lazy_static would be deprecated after rust 1.70
# https://github.com/rust-lang-nursery/lazy-static.rs/issues/214
lazy_static = "1.4"
log = "0.4"
structopt = "0.3"
strum = { version = "0.21.0", features = ["derive"] }
strum = { version = "0.26.3", features = ["derive"] }
derive_macro_tool = { path = "derive_macro" }
proc-macro2 = { version = "1.0", default-features = false }
quote = "1.0"
syn = { version = "1.0", features = ["extra-traits", "clone-impls"] }
heck = "0.3"
syn = { version = "2.0.72", features = ["extra-traits", "clone-impls"] }
heck = "0.5.0"
paste = "1.0"
toml = "0.5"
serde = { version = "1.0", features = ["derive"] }
toml = "0.8.16"
serde = { version = "1", features = ["derive"] }


[dev-dependencies]
axum = { version = "0.6.0", features = ["headers"] }
axum = "0.7.5"
axum-extra = "0.9.3"
tokio = { version = "1.8", features = ["macros", "rt-multi-thread"] }
async-graphql-axum = "6.0.1"
async-graphql-axum = "7.0.7"
26 changes: 25 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub enum Phase {
Enums,
}

#[derive(Deserialize, Default, Debug)]
#[derive(Deserialize, Debug)]
pub struct RendererConfig {
pub using: Option<HashMap<String, String>>,
#[serde(default = "RendererConfig::default_data_source_fetch_method_from_ctx")]
Expand Down Expand Up @@ -299,3 +299,27 @@ impl RendererConfig {
Ok(config)
}
}

impl Default for RendererConfig {
fn default() -> Self {
Self {
using: None,
data_source_fetch_method: RendererConfig::default_data_source_fetch_method_from_ctx(),
custom_member_types: None,
resolver: None,
additional_resolver: None,
hidden_field: None,
additional: None,
ignore: None,
r#enum: None,
field: None,
enum_rename_items: None,
header: RendererConfig::default_header(),
resolver_type: None,
additional_attributes: None,
phases: vec![],
no_object_impl: false,
no_dependency_imports: false,
}
}
}
6 changes: 3 additions & 3 deletions src/render/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::sorter::sort_by_line_pos_and_name;
use super::tokens::*;
use crate::config::{EnumSetting, EnumValueSetting, RendererConfig};
use anyhow::Result;
use heck::CamelCase;
use heck::ToUpperCamelCase;
use proc_macro2::TokenStream;
use quote::*;
use std::collections::HashMap;
Expand Down Expand Up @@ -75,7 +75,7 @@ fn enum_token(
config: &RendererConfig,
enum_settings: &HashMap<String, EnumSetting>,
) -> Result<TokenStream> {
let enum_name = enm.name.to_camel_case();
let enum_name = enm.name.to_upper_camel_case();
let mut graphql_derive = quote! {};

// TODO(tacogips) using there_is_specific_rename_item is naive implementation. make this concise with macro or something
Expand All @@ -102,7 +102,7 @@ fn enum_token(
.iter()
.map(|each_enum_value| {
//each_enum.value_name.parse::<TokenStream>().unwrap()}
let enum_value_name = each_enum_value.value_name.to_camel_case();
let enum_value_name = each_enum_value.value_name.to_upper_camel_case();
let each_enum = format_ident!("{}", enum_value_name);

let enum_attribute = match enum_value_settings.get(&enum_value_name) {
Expand Down
4 changes: 2 additions & 2 deletions src/render/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::utils::SnakeCaseWithUnderscores;
use super::RenderContext;
use crate::config::RendererConfig;
use anyhow::Result;
use heck::CamelCase;
use heck::ToUpperCamelCase;
use proc_macro2::TokenStream;
use quote::*;
use std::collections::HashMap;
Expand Down Expand Up @@ -170,7 +170,7 @@ fn convert_interface_member(
render_context: &RenderContext,
) -> Result<InterfaceMember> {
let member_type_name = format_ident!("{}", member);
let member_enum_name = format_ident!("{}", member.to_camel_case());
let member_enum_name = format_ident!("{}", member.to_upper_camel_case());

//TODO(tacogips) this conversion of interface member type to ValueTypeDef might be a bit hack-y?
let member_type = ValueTypeDef::Named(NamedValue {
Expand Down
18 changes: 6 additions & 12 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,45 +74,39 @@ pub fn output_schema(
setup_output_dir(output_dir)?;

let objects_written = if config.phases.is_empty() || config.phases.contains(&Phase::Objects) {
objects::write_objects(output_dir, &structured_schema, &config)?;
true
objects::write_objects(output_dir, &structured_schema, &config)?
} else {
false
};

let input_objects_written =
if config.phases.is_empty() || config.phases.contains(&Phase::InputObjects) {
input_objects::write_input_objects(output_dir, &structured_schema)?;
true
input_objects::write_input_objects(output_dir, &structured_schema)?
} else {
false
};

let union_written = if config.phases.is_empty() || config.phases.contains(&Phase::Unions) {
unions::write_unions(output_dir, &structured_schema)?;
true
unions::write_unions(output_dir, &structured_schema)?
} else {
false
};

let scalar_written = if config.phases.is_empty() || config.phases.contains(&Phase::Scalars) {
scalars::write_scalars(output_dir, &structured_schema)?;
true
scalars::write_scalars(output_dir, &structured_schema)?
} else {
false
};

let interface_written =
if config.phases.is_empty() || config.phases.contains(&Phase::Interfaces) {
interfaces::write_interfaces(output_dir, &structured_schema, &config)?;
true
interfaces::write_interfaces(output_dir, &structured_schema, &config)?
} else {
false
};

let enum_written = if config.phases.is_empty() || config.phases.contains(&Phase::Enums) {
enums::write_enums(output_dir, &structured_schema, &config)?;
true
enums::write_enums(output_dir, &structured_schema, &config)?
} else {
false
};
Expand Down
4 changes: 2 additions & 2 deletions src/render/unions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::sorter::sort_by_line_pos_and_name;
use super::tokens::*;
use super::RenderContext;
use anyhow::Result;
use heck::CamelCase;
use heck::ToUpperCamelCase;
use proc_macro2::TokenStream;
use quote::*;
use std::collections::HashSet;
Expand Down Expand Up @@ -145,7 +145,7 @@ fn convert_union_member(
render_context: &RenderContext,
) -> Result<UnionMember> {
let member_type_name = format_ident!("{}", member);
let member_enum_name = format_ident!("{}", member.to_camel_case());
let member_enum_name = format_ident!("{}", member.to_upper_camel_case());

//TODO(tacogips) this conversion of union member type to ValueTypeDef might be a bit hack-y?
let member_type = ValueTypeDef::Named(NamedValue {
Expand Down
2 changes: 1 addition & 1 deletion src/render/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use heck::SnakeCase;
use heck::ToSnakeCase;

pub trait SnakeCaseWithUnderscores: ToOwned {
/// Convert this type to snake case without trimming leading / trailing underscores
Expand Down

0 comments on commit 8542847

Please sign in to comment.