Skip to content

Commit

Permalink
fix #533 in which a default arg was marked as required
Browse files Browse the repository at this point in the history
  • Loading branch information
imor committed Jun 25, 2024
1 parent eeafeda commit 3e2628b
Show file tree
Hide file tree
Showing 3 changed files with 554 additions and 1 deletion.
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

0 comments on commit 3e2628b

Please sign in to comment.