Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #533 in which a default arg was marked as required #534

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/sql_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,12 @@ impl<'a> ArgsIterator<'a> {

fn sql_to_graphql_default(default_str: &str, type_oid: u32) -> Option<DefaultValue> {
let trimmed = default_str.trim();

if trimmed.starts_with("NULL::") {
return Some(DefaultValue::Null);
}
match type_oid {

let res = match type_oid {
21 | 23 => trimmed
.parse::<i32>()
.ok()
Expand All @@ -283,6 +285,16 @@ impl<'a> ArgsIterator<'a> {
DefaultValue::NonNull(format!("\"{}\"", i.trim_matches(',').trim_matches('\'')))
}),
_ => None,
};

// return the non-parsed value as default if for whatever reason the default value can't
// be parsed into a value of the required type. This fixes problems where the default
// is a complex expression like a function call etc. See test/sql/issue_533.sql for
// a test case for this scenario.
if res.is_some() {
res
} else {
Some(DefaultValue::NonNull(trimmed.to_string()))
}
}
}
Expand Down
Loading
Loading