From 975a74fd0f935b6fc718e8e0919205534f4198fc Mon Sep 17 00:00:00 2001 From: Raminder Singh Date: Mon, 9 Oct 2023 14:07:35 +0530 Subject: [PATCH 1/2] do not expose trigger functions in GQL --- src/sql_types.rs | 2 ++ test/expected/function_calls.out | 6 ++++++ test/sql/function_calls.sql | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/src/sql_types.rs b/src/sql_types.rs index 9b973d00..63e20548 100644 --- a/src/sql_types.rs +++ b/src/sql_types.rs @@ -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 diff --git a/test/expected/function_calls.out b/test/expected/function_calls.out index 5a178290..1be22c5e 100644 --- a/test/expected/function_calls.out +++ b/test/expected/function_calls.out @@ -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 { diff --git a/test/sql/function_calls.sql b/test/sql/function_calls.sql index fee57898..b2be9339 100644 --- a/test/sql/function_calls.sql +++ b/test/sql/function_calls.sql @@ -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 { From 3b38221cb174eabc4ff8cf040f98678b8a2c340b Mon Sep 17 00:00:00 2001 From: Raminder Singh Date: Mon, 9 Oct 2023 14:13:15 +0530 Subject: [PATCH 2/2] add calls to trigger functions in test --- test/expected/function_calls.out | 34 ++++++++++++++++++++++++++++++++ test/sql/function_calls.sql | 12 +++++++++++ 2 files changed, 46 insertions(+) diff --git a/test/expected/function_calls.out b/test/expected/function_calls.out index 1be22c5e..a99a65dc 100644 --- a/test/expected/function_calls.out +++ b/test/expected/function_calls.out @@ -2161,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; diff --git a/test/sql/function_calls.sql b/test/sql/function_calls.sql index b2be9339..4f1b0b07 100644 --- a/test/sql/function_calls.sql +++ b/test/sql/function_calls.sql @@ -770,4 +770,16 @@ begin; concatText(a: "hello ") } $$)); + + select jsonb_pretty(graphql.resolve($$ + query { + returnsTrigger + } + $$)); + + select jsonb_pretty(graphql.resolve($$ + query { + returnsEventTrigger + } + $$)); rollback;