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 a bug in extracting default values from function arguments #462

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading