You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
i create customer using insertIntoCustomerCollection with data,
In database i create an account for this customer using before insert trigger,
then i assign account id to this customer record.
here i got account id, but pg-graphql wont populate account table.
it is populated on update & get.
To Reproduce
Steps to reproduce the behavior:
create table customer
createtableif not exists customer
(
id intnot null generated always as identity primary key,
name textnot null,
. . .
. . .
tracking_account booleannot null default false,
credit_account int
);
create trigger:
createtriggercreate_update_customer_account
before insert orupdateon customer
for each row
when (new.tracking_account)
execute procedure create_update_credit_account();
create account table:
createtableif not exists account
(
id intnot null GENERATED BY default as identity (start with 101 increment by 1) primary key,
name textnot null,
account_type textnot null
. . .
. . .
);
create function for above trigger
createfunctioncreate_update_credit_account()
returns trigger as
$$
declare
. . .
begin
if tg_op ='INSERT' then
. . .
insert into account(name, account_type, . . . tracked)
values (new.name, acc_type, . . .,true)
returning id into new.credit_account;
else
update account
set name =new.name,
. . .
. . .
where id =new.credit_account;
end if;
return new;
end;
$$ language plpgsql;
Expected behavior
it should return object created via before insert trigger
Screenshots
create customer:
get customer:
Versions:
PostgreSQL: 16
pg_graphql: 1.5.5
The text was updated successfully, but these errors were encountered:
createtableif not exists customer (
id intnot null generated always as identity primary key,
name textnot null
);
createtableif not exists account (
id intprimary key
);
create or replacefunctioncreate_update_credit_account()
returns trigger as
$$
declare
begin
if tg_op ='INSERT' then
insert into account(id)
values (new.id);
end if;
return new;
end;
$$ language plpgsql;
createtriggercreate_update_customer_account
before insert orupdateon customer
for each row
execute procedure create_update_credit_account();
-- This is roughly what the GraphQL query turns into
with affected as (
insert into customer(name)
values ('foo')
returning id, name
)
selectaff.id,
aff.name,
acc.idas account_id
from
affected aff
left join account acc
onaff.id=acc.id
Returns:
id
name
account_id
1
foo
null
So unfortunately this is a limitation in SQL and not something we can fix in pg_graphql
If anyone is aware of a way to restructure the SQL to be able to return the account record from an insert statement please let me know
Describe the bug
i create customer using insertIntoCustomerCollection with data,
In database i create an account for this customer using before insert trigger,
then i assign account id to this customer record.
here i got account id, but pg-graphql wont populate account table.
it is populated on update & get.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
it should return object created via before insert trigger
Screenshots
create customer:
get customer:
Versions:
The text was updated successfully, but these errors were encountered: