Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cli-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ jobs:
./bin/psql -p 54322 -h 127.0.0.1 -U supabase_admin -d postgres -v ON_ERROR_STOP=1 -c "\dx" | tee extensions.log

# Check for required extensions
for ext in pg_graphql pgcrypto uuid-ossp supabase_vault; do
for ext in pgcrypto uuid-ossp supabase_vault; do
if ! grep -q "$ext" extensions.log; then
echo "Required extension $ext not found"
exit 1
Expand Down
6 changes: 3 additions & 3 deletions ansible/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ postgres_major:

# Full version strings for each major version
postgres_release:
postgresorioledb-17: "17.6.0.066-orioledb"
postgres17: "17.6.1.109"
postgres15: "15.14.1.109"
postgresorioledb-17: "17.6.0.065-orioledb-gql-off"
postgres17: "17.6.1.108-gql-off"
postgres15: "15.14.1.108-gql-off"

# Non Postgres Extensions
pgbouncer_release: 1.25.1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- migrate:up
drop extension if exists pg_graphql;

-- migrate:down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-- migrate:up

create or replace function extensions.grant_pg_graphql_access()
returns event_trigger
language plpgsql
as $func$
begin
if not exists (
select 1
from pg_event_trigger_ddl_commands() ev
join pg_catalog.pg_extension e on ev.objid = e.oid
where e.extname = 'pg_graphql'
) then
return;
end if;

drop function if exists graphql_public.graphql;
create or replace function graphql_public.graphql(
"operationName" text default null,
query text default null,
variables jsonb default null,
extensions jsonb default null
)
returns jsonb
language sql
as $$
select graphql.resolve(
query := query,
variables := coalesce(variables, '{}'),
"operationName" := "operationName",
extensions := extensions
);
$$;

-- Attach the wrapper to the extension so DROP EXTENSION cascades to it,
-- which in turn triggers set_graphql_placeholder to reinstall the "not enabled" stub.
alter extension pg_graphql add function graphql_public.graphql(text, text, jsonb, jsonb);

grant usage on schema graphql to postgres, anon, authenticated, service_role;
grant execute on function graphql.resolve to postgres, anon, authenticated, service_role;
grant usage on schema graphql to postgres with grant option;
grant usage on schema graphql_public to postgres with grant option;
end;
$func$;

drop event trigger if exists issue_pg_graphql_access;
create event trigger issue_pg_graphql_access
on ddl_command_end
when tag in ('CREATE EXTENSION')
execute procedure extensions.grant_pg_graphql_access();

-- migrate:down
134 changes: 71 additions & 63 deletions migrations/schema-15.sql
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,6 @@ CREATE SCHEMA storage;
CREATE SCHEMA vault;


--
-- Name: pg_graphql; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS pg_graphql WITH SCHEMA graphql;


--
-- Name: EXTENSION pg_graphql; Type: COMMENT; Schema: -; Owner: -
--

COMMENT ON EXTENSION pg_graphql IS 'pg_graphql: GraphQL support';


--
-- Name: pg_stat_statements; Type: EXTENSION; Schema: -; Owner: -
--
Expand Down Expand Up @@ -228,54 +214,43 @@ COMMENT ON FUNCTION extensions.grant_pg_cron_access() IS 'Grants access to pg_cr
CREATE FUNCTION extensions.grant_pg_graphql_access() RETURNS event_trigger
LANGUAGE plpgsql
AS $_$
DECLARE
func_is_graphql_resolve bool;
BEGIN
func_is_graphql_resolve = (
SELECT n.proname = 'resolve'
FROM pg_event_trigger_ddl_commands() AS ev
LEFT JOIN pg_catalog.pg_proc AS n
ON ev.objid = n.oid
);

IF func_is_graphql_resolve
THEN
-- Update public wrapper to pass all arguments through to the pg_graphql resolve func
DROP FUNCTION IF EXISTS graphql_public.graphql;
create or replace function graphql_public.graphql(
"operationName" text default null,
query text default null,
variables jsonb default null,
extensions jsonb default null
)
returns jsonb
language sql
as $$
select graphql.resolve(
query := query,
variables := coalesce(variables, '{}'),
"operationName" := "operationName",
extensions := extensions
);
$$;

-- This hook executes when `graphql.resolve` is created. That is not necessarily the last
-- function in the extension so we need to grant permissions on existing entities AND
-- update default permissions to any others that are created after `graphql.resolve`
grant usage on schema graphql to postgres, anon, authenticated, service_role;
grant select on all tables in schema graphql to postgres, anon, authenticated, service_role;
grant execute on all functions in schema graphql to postgres, anon, authenticated, service_role;
grant all on all sequences in schema graphql to postgres, anon, authenticated, service_role;
alter default privileges in schema graphql grant all on tables to postgres, anon, authenticated, service_role;
alter default privileges in schema graphql grant all on functions to postgres, anon, authenticated, service_role;
alter default privileges in schema graphql grant all on sequences to postgres, anon, authenticated, service_role;

-- Allow postgres role to allow granting usage on graphql and graphql_public schemas to custom roles
grant usage on schema graphql_public to postgres with grant option;
grant usage on schema graphql to postgres with grant option;
END IF;

END;
begin
if not exists (
select 1
from pg_event_trigger_ddl_commands() ev
join pg_catalog.pg_extension e on ev.objid = e.oid
where e.extname = 'pg_graphql'
) then
return;
end if;

drop function if exists graphql_public.graphql;
create or replace function graphql_public.graphql(
"operationName" text default null,
query text default null,
variables jsonb default null,
extensions jsonb default null
)
returns jsonb
language sql
as $$
select graphql.resolve(
query := query,
variables := coalesce(variables, '{}'),
"operationName" := "operationName",
extensions := extensions
);
$$;

-- Attach the wrapper to the extension so DROP EXTENSION cascades to it,
-- which in turn triggers set_graphql_placeholder to reinstall the "not enabled" stub.
alter extension pg_graphql add function graphql_public.graphql(text, text, jsonb, jsonb);

grant usage on schema graphql to postgres, anon, authenticated, service_role;
grant execute on function graphql.resolve to postgres, anon, authenticated, service_role;
grant usage on schema graphql to postgres with grant option;
grant usage on schema graphql_public to postgres with grant option;
end;
$_$;


Expand Down Expand Up @@ -472,6 +447,39 @@ $_$;
COMMENT ON FUNCTION extensions.set_graphql_placeholder() IS 'Reintroduces placeholder function for graphql_public.graphql';


--
-- Name: graphql(text, text, jsonb, jsonb); Type: FUNCTION; Schema: graphql_public; Owner: -
--

CREATE FUNCTION graphql_public.graphql("operationName" text DEFAULT NULL::text, query text DEFAULT NULL::text, variables jsonb DEFAULT NULL::jsonb, extensions jsonb DEFAULT NULL::jsonb) RETURNS jsonb
LANGUAGE plpgsql
AS $$
DECLARE
server_version float;
BEGIN
server_version = (SELECT (SPLIT_PART((select version()), ' ', 2))::float);

IF server_version >= 14 THEN
RETURN jsonb_build_object(
'errors', jsonb_build_array(
jsonb_build_object(
'message', 'pg_graphql extension is not enabled.'
)
)
);
ELSE
RETURN jsonb_build_object(
'errors', jsonb_build_array(
jsonb_build_object(
'message', 'pg_graphql is only available on projects running Postgres 14 onwards.'
)
)
);
END IF;
END;
$$;


--
-- Name: get_auth(text); Type: FUNCTION; Schema: pgbouncer; Owner: -
--
Expand Down Expand Up @@ -776,7 +784,7 @@ CREATE EVENT TRIGGER issue_pg_cron_access ON ddl_command_end
--

CREATE EVENT TRIGGER issue_pg_graphql_access ON ddl_command_end
WHEN TAG IN ('CREATE FUNCTION')
WHEN TAG IN ('CREATE EXTENSION')
EXECUTE FUNCTION extensions.grant_pg_graphql_access();


Expand Down
Loading
Loading