Skip to content

Commit

Permalink
Merge pull request #462 from supabase/fix_461
Browse files Browse the repository at this point in the history
fix a bug in extracting default values from function arguments
  • Loading branch information
olirice authored Dec 1, 2023
2 parents 6f88f13 + 275f797 commit 1050bc7
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 112 deletions.
2 changes: 1 addition & 1 deletion src/sql_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl<'a> ArgsIterator<'a> {
let start_idx = num_total_args - num_default_args;
for i in start_idx..num_total_args {
defaults[i] =
Self::sql_to_graphql_default(default_strs[i - start_idx], arg_types[i - start_idx])
Self::sql_to_graphql_default(default_strs[i - start_idx], arg_types[i])
}

defaults
Expand Down
235 changes: 124 additions & 111 deletions test/expected/function_calls.out
Original file line number Diff line number Diff line change
Expand Up @@ -2310,6 +2310,7 @@ begin;
returns smallint language sql immutable
as $$ select a + b; $$;
create function func_with_defaults(
arg_without_a_default int,
a smallint default 1,
b integer default 2,
c boolean default false,
Expand Down Expand Up @@ -2351,117 +2352,129 @@ begin;
}
$$)
);
jsonb_pretty
-------------------------------------------------------------
{ +
"data": { +
"__schema": { +
"queryType": { +
"name": "Query", +
"fields": [ +
{ +
"args": [ +
{ +
"name": "a", +
"type": { +
"kind": "SCALAR", +
"name": "Int", +
"ofType": null +
}, +
"defaultValue": "1" +
}, +
{ +
"name": "b", +
"type": { +
"kind": "SCALAR", +
"name": "Int", +
"ofType": null +
}, +
"defaultValue": "2" +
} +
], +
"name": "addSmallints" +
}, +
{ +
"args": [ +
{ +
"name": "a", +
"type": { +
"kind": "SCALAR", +
"name": "Int", +
"ofType": null +
}, +
"defaultValue": "1" +
}, +
{ +
"name": "b", +
"type": { +
"kind": "SCALAR", +
"name": "Int", +
"ofType": null +
}, +
"defaultValue": "2" +
}, +
{ +
"name": "c", +
"type": { +
"kind": "SCALAR", +
"name": "Boolean", +
"ofType": null +
}, +
"defaultValue": "false" +
}, +
{ +
"name": "d", +
"type": { +
"kind": "SCALAR", +
"name": "Float", +
"ofType": null +
}, +
"defaultValue": "3.14" +
}, +
{ +
"name": "e", +
"type": { +
"kind": "SCALAR", +
"name": "Float", +
"ofType": null +
}, +
"defaultValue": "2.718" +
}, +
{ +
"name": "f", +
"type": { +
"kind": "SCALAR", +
"name": "String", +
"ofType": null +
}, +
"defaultValue": "\"hello\""+
} +
], +
"name": "funcWithDefaults" +
}, +
{ +
"args": [ +
{ +
"name": "nodeId", +
"type": { +
"kind": "NON_NULL", +
"name": null, +
"ofType": { +
"kind": "SCALAR", +
"name": "ID" +
} +
}, +
"defaultValue": null +
} +
], +
"name": "node" +
} +
] +
} +
} +
} +
jsonb_pretty
---------------------------------------------------------------
{ +
"data": { +
"__schema": { +
"queryType": { +
"name": "Query", +
"fields": [ +
{ +
"args": [ +
{ +
"name": "a", +
"type": { +
"kind": "SCALAR", +
"name": "Int", +
"ofType": null +
}, +
"defaultValue": "1" +
}, +
{ +
"name": "b", +
"type": { +
"kind": "SCALAR", +
"name": "Int", +
"ofType": null +
}, +
"defaultValue": "2" +
} +
], +
"name": "addSmallints" +
}, +
{ +
"args": [ +
{ +
"name": "argWithoutADefault",+
"type": { +
"kind": "NON_NULL", +
"name": null, +
"ofType": { +
"kind": "SCALAR", +
"name": "Int" +
} +
}, +
"defaultValue": null +
}, +
{ +
"name": "a", +
"type": { +
"kind": "SCALAR", +
"name": "Int", +
"ofType": null +
}, +
"defaultValue": "1" +
}, +
{ +
"name": "b", +
"type": { +
"kind": "SCALAR", +
"name": "Int", +
"ofType": null +
}, +
"defaultValue": "2" +
}, +
{ +
"name": "c", +
"type": { +
"kind": "SCALAR", +
"name": "Boolean", +
"ofType": null +
}, +
"defaultValue": "false" +
}, +
{ +
"name": "d", +
"type": { +
"kind": "SCALAR", +
"name": "Float", +
"ofType": null +
}, +
"defaultValue": "3.14" +
}, +
{ +
"name": "e", +
"type": { +
"kind": "SCALAR", +
"name": "Float", +
"ofType": null +
}, +
"defaultValue": "2.718" +
}, +
{ +
"name": "f", +
"type": { +
"kind": "SCALAR", +
"name": "String", +
"ofType": null +
}, +
"defaultValue": "\"hello\"" +
} +
], +
"name": "funcWithDefaults" +
}, +
{ +
"args": [ +
{ +
"name": "nodeId", +
"type": { +
"kind": "NON_NULL", +
"name": null, +
"ofType": { +
"kind": "SCALAR", +
"name": "ID" +
} +
}, +
"defaultValue": null +
} +
], +
"name": "node" +
} +
] +
} +
} +
} +
}
(1 row)

Expand Down
1 change: 1 addition & 0 deletions test/sql/function_calls.sql
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ begin;
as $$ select a + b; $$;

create function func_with_defaults(
arg_without_a_default int,
a smallint default 1,
b integer default 2,
c boolean default false,
Expand Down

0 comments on commit 1050bc7

Please sign in to comment.