Skip to content

Commit

Permalink
Merge pull request #432 from supabase/fix/filter-trigger-funcs
Browse files Browse the repository at this point in the history
do not expose trigger functions in GQL
  • Loading branch information
imor authored Oct 9, 2023
2 parents aeb1801 + 3b38221 commit 6b9006b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/sql_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ impl Function {
if let Some(return_type) = types.get(&self.type_oid) {
return_type.category != TypeCategory::Pseudo
&& return_type.name != "record"
&& return_type.name != "trigger"
&& return_type.name != "event_trigger"
&& !self.type_name.ends_with("[]")
} else {
false
Expand Down
40 changes: 40 additions & 0 deletions test/expected/function_calls.out
Original file line number Diff line number Diff line change
Expand Up @@ -1954,6 +1954,12 @@ begin;
)
returns smallint language sql immutable
as $$ select 0; $$;
create function returns_trigger()
returns trigger language plpgsql immutable
as $$ begin return null; end; $$;
create function returns_event_trigger()
returns event_trigger language plpgsql immutable
as $$ begin end; $$;
select jsonb_pretty(
graphql.resolve($$
query IntrospectionQuery {
Expand Down Expand Up @@ -2155,4 +2161,38 @@ begin;
}
(1 row)

select jsonb_pretty(graphql.resolve($$
query {
returnsTrigger
}
$$));
jsonb_pretty
-------------------------------------------------------------------------
{ +
"data": null, +
"errors": [ +
{ +
"message": "Unknown field \"returnsTrigger\" on type Query"+
} +
] +
}
(1 row)

select jsonb_pretty(graphql.resolve($$
query {
returnsEventTrigger
}
$$));
jsonb_pretty
------------------------------------------------------------------------------
{ +
"data": null, +
"errors": [ +
{ +
"message": "Unknown field \"returnsEventTrigger\" on type Query"+
} +
] +
}
(1 row)

rollback;
20 changes: 20 additions & 0 deletions test/sql/function_calls.sql
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,14 @@ begin;
returns smallint language sql immutable
as $$ select 0; $$;

create function returns_trigger()
returns trigger language plpgsql immutable
as $$ begin return null; end; $$;

create function returns_event_trigger()
returns event_trigger language plpgsql immutable
as $$ begin end; $$;

select jsonb_pretty(
graphql.resolve($$
query IntrospectionQuery {
Expand Down Expand Up @@ -762,4 +770,16 @@ begin;
concatText(a: "hello ")
}
$$));

select jsonb_pretty(graphql.resolve($$
query {
returnsTrigger
}
$$));

select jsonb_pretty(graphql.resolve($$
query {
returnsEventTrigger
}
$$));
rollback;

0 comments on commit 6b9006b

Please sign in to comment.