Skip to content

Commit 3e2628b

Browse files
committed
fix #533 in which a default arg was marked as required
1 parent eeafeda commit 3e2628b

File tree

3 files changed

+554
-1
lines changed

3 files changed

+554
-1
lines changed

src/sql_types.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,12 @@ impl<'a> ArgsIterator<'a> {
263263

264264
fn sql_to_graphql_default(default_str: &str, type_oid: u32) -> Option<DefaultValue> {
265265
let trimmed = default_str.trim();
266+
266267
if trimmed.starts_with("NULL::") {
267268
return Some(DefaultValue::Null);
268269
}
269-
match type_oid {
270+
271+
let res = match type_oid {
270272
21 | 23 => trimmed
271273
.parse::<i32>()
272274
.ok()
@@ -283,6 +285,16 @@ impl<'a> ArgsIterator<'a> {
283285
DefaultValue::NonNull(format!("\"{}\"", i.trim_matches(',').trim_matches('\'')))
284286
}),
285287
_ => None,
288+
};
289+
290+
// return the non-parsed value as default if for whatever reason the default value can't
291+
// be parsed into a value of the required type. This fixes problems where the default
292+
// is a complex expression like a function call etc. See test/sql/issue_533.sql for
293+
// a test case for this scenario.
294+
if res.is_some() {
295+
res
296+
} else {
297+
Some(DefaultValue::NonNull(trimmed.to_string()))
286298
}
287299
}
288300
}

0 commit comments

Comments
 (0)