-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #512 from supabase/fix_511
fix issue #511
- Loading branch information
Showing
3 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |