// lowerCaseEnums.ts
export function lowerCaseEnums(builder: any) {
builder.hook('inflection', (inflection: any) => ({
...inflection,
enumName(value: string) {
return value.toLowerCase();
}
}));
}
// index.ts
app.use(
postgraphile(getDbPool(), 'schema_name', {
appendPlugins: [lowerCaseEnums]
})
);
[ { error: ROLLBACK TO SAVEPOINT can only be used in transaction blocks
at Connection.parseE (/XXXXXXXXX/react-postgraphile/react-postgraphile-front/node_modules/pg/lib/connection.js:553:11)
"pg": "^7.4.3",
"pg-pool": "^2.0.3",
"postgraphile": "^4.0.0-rc.2",
Should I be using different versions?
if (needTransaction) {
console.log('BEGIN TRANSACTION');
await pgClient.query('begin');
}
I'm generating error messages for the front end like this:
create or replace function app_public.register_person(
handle text,
display_name text,
email text,
password text
) returns app_public.person as $$
declare
person app_public.person;
constraint_name text;
begin
insert into app_public.person (handle, display_name) values
(handle, display_name)
returning * into person;
insert into app_private.person_account (person_id, email, password_hash) values
(person.id, email, crypt(password, gen_salt('bf')));
return person;
exception
when check_violation then
get stacked diagnostics constraint_name = CONSTRAINT_NAME;
if constraint_name = 'handle_length' then
raise exception 'Your handle is too long';
end if;
when unique_violation then
get stacked diagnostics constraint_name = CONSTRAINT_NAME;
if constraint_name = 'person_account_email_key' then
raise exception 'That email is already in use';
elsif constraint_name = 'person_handle_key' then
raise exception 'That handle is already in use';
else
raise exception '%', constraint_name;
end if;
end;
$$ language plpgsql strict security definer;
It works, but I'm curious as to whether this is the "right" approach or not.
graphile-utils
to make plugin factories to make doing things a lot easier for people. For example, there really should be an inflector
plugin factory that enables you to override the inflector. Anyway I'm getting ahead of myself.