Skip to content

Commit

Permalink
Merge pull request #512 from supabase/fix_511
Browse files Browse the repository at this point in the history
fix issue #511
  • Loading branch information
olirice authored Apr 15, 2024
2 parents b0032a5 + 047dcf0 commit 45a624f
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ impl FunctionBuilder {
from
{from_clause} as {func_block_name}
where
{func_block_name} is not null
not ({func_block_name} is null)
)
"
)
Expand Down
88 changes: 88 additions & 0 deletions test/expected/issue_511.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
begin;
create table users(
id uuid primary key,
email character varying (255),
phone text
);
insert into public.users(id, email, phone)
values
('dd5add8a-7dd2-4495-bc1a-a1dfe95ef23a', '[email protected]', '987654321'),
('12e684cc-b7c2-492e-8554-9ab3e03fa37f', null, null),
('748a81bb-5f71-4dc8-88d9-efe9f03a14b8', null, '123456789');
create or replace view users_with_phone as select
id,
email,
phone
from public.users
where phone is not null;
create table polls(
id uuid primary key,
user_id uuid references users(id)
);
insert into public.polls(id, user_id)
values
('98813159-4814-42fa-911d-5cc900bd80b8', 'dd5add8a-7dd2-4495-bc1a-a1dfe95ef23a'),
('07dc0104-3811-4a5d-8887-4018c8116e5c', '12e684cc-b7c2-492e-8554-9ab3e03fa37f'),
('3bec2818-7bea-40ba-81fa-7d0ba061c3de', '748a81bb-5f71-4dc8-88d9-efe9f03a14b8');
create
or replace function author (rec polls) returns users_with_phone stable strict language sql security definer
set
search_path = public as $$
select
*
from users_with_phone u
where u.id = $1.user_id;
$$;
select jsonb_pretty(
graphql.resolve($$
{
pollsCollection {
edges {
node {
author {
id,
email,
phone
}
}
}
}
}
$$)
);
jsonb_pretty
---------------------------------------------------------------------------
{ +
"data": { +
"pollsCollection": { +
"edges": [ +
{ +
"node": { +
"author": null +
} +
}, +
{ +
"node": { +
"author": { +
"id": "748a81bb-5f71-4dc8-88d9-efe9f03a14b8",+
"email": null, +
"phone": "123456789" +
} +
} +
}, +
{ +
"node": { +
"author": { +
"id": "dd5add8a-7dd2-4495-bc1a-a1dfe95ef23a",+
"email": "[email protected]", +
"phone": "987654321" +
} +
} +
} +
] +
} +
} +
}
(1 row)

rollback;
61 changes: 61 additions & 0 deletions test/sql/issue_511.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
begin;

create table users(
id uuid primary key,
email character varying (255),
phone text
);

insert into public.users(id, email, phone)
values
('dd5add8a-7dd2-4495-bc1a-a1dfe95ef23a', '[email protected]', '987654321'),
('12e684cc-b7c2-492e-8554-9ab3e03fa37f', null, null),
('748a81bb-5f71-4dc8-88d9-efe9f03a14b8', null, '123456789');

create or replace view users_with_phone as select
id,
email,
phone
from public.users
where phone is not null;

create table polls(
id uuid primary key,
user_id uuid references users(id)
);

insert into public.polls(id, user_id)
values
('98813159-4814-42fa-911d-5cc900bd80b8', 'dd5add8a-7dd2-4495-bc1a-a1dfe95ef23a'),
('07dc0104-3811-4a5d-8887-4018c8116e5c', '12e684cc-b7c2-492e-8554-9ab3e03fa37f'),
('3bec2818-7bea-40ba-81fa-7d0ba061c3de', '748a81bb-5f71-4dc8-88d9-efe9f03a14b8');

create
or replace function author (rec polls) returns users_with_phone stable strict language sql security definer
set
search_path = public as $$
select
*
from users_with_phone u
where u.id = $1.user_id;
$$;

select jsonb_pretty(
graphql.resolve($$
{
pollsCollection {
edges {
node {
author {
id,
email,
phone
}
}
}
}
}
$$)
);

rollback;

0 comments on commit 45a624f

Please sign in to comment.