S
Supabase7d ago
Oz

Type generation error

Hello! I'm trying to generate types for one of my projects via CLI but it throws error:
failed to retrieve generated types: {"message":"failed to determine PostgREST version for project <my_project_id>: {\"code\":\"PGRST126\",\"details\":null,\"hint\":null,\"message\":\"Root endpoint metadata is disabled\"}"}
failed to retrieve generated types: {"message":"failed to determine PostgREST version for project <my_project_id>: {\"code\":\"PGRST126\",\"details\":null,\"hint\":null,\"message\":\"Root endpoint metadata is disabled\"}"}
It works for my other project though. Any help? Thank you!
7 Replies
silentworks
silentworks7d ago
Did you disable your Data API by any chance? Go here and check if it's disabled https://supabase.com/dashboard/project/_/settings/api
Idris
Idris7d ago
To me it seems like he hasnt even configured the project id in config.toml It says <my_project_id> in the error
silentworks
silentworks7d ago
Maybe the user omitted that from the message when they posted it.
Idris
Idris7d ago
Ohh I am stupid haha. Thought he just had that in his config haha
Oz
OzOP7d ago
Okay, I found it. I was trying to harden my setup and followed the suggestion on this github post (https://github.com/orgs/supabase/discussions/12439)
You can turn off the REST OPEN API endpoint by returning fake info. https://postgrest.org/en/v12/references/api/openapi.html#overriding-full-openapi-response Also make sure you run:

alter role authenticator
set pgrst.db_root_spec = 'public.root';
after you add that function...
You can turn off the REST OPEN API endpoint by returning fake info. https://postgrest.org/en/v12/references/api/openapi.html#overriding-full-openapi-response Also make sure you run:

alter role authenticator
set pgrst.db_root_spec = 'public.root';
after you add that function...
this of course affected the type generation. thank you @silentworks for your insight!
GitHub
Can my database schema and views viewed by anyone? · supabase · D...
Hello guys, we are using Supabase in a NextJS application and we are very happy with it. All our tables are stored in the (default) public schema. For our server side code we initialize a client th...
silentworks
silentworks7d ago
Nah it was a good thing to point out when trying to help someone as sometimes folks do mess with this and it causes issues. Yeah without the Data API there is no way to get the type generation with the CLI.
vick
vick5d ago
Maybe it depends on what your function is returning. This is how I define it and it has never affected type generation for me:
-- hide the auto-generated API schema at the /rest/v1/ endpoint
CREATE OR REPLACE FUNCTION pg_rest_root() RETURNS JSON AS $_$
DECLARE
openapi JSON = $${"swagger": "2.0","info":{"title":"Private API","description":"This is not a public API. Stop snooping."}}$$;
BEGIN
RETURN openapi;
END
$_$ LANGUAGE plpgsql IMMUTABLE PARALLEL SAFE SET search_path = '';

COMMENT ON FUNCTION pg_rest_root() IS 'Hide the OpenAPI schema for the /rest/v1/ endpoint.';

ALTER ROLE authenticator SET pgrst.db_root_spec = 'public.pg_rest_root';
NOTIFY pgrst, 'reload config';
-- hide the auto-generated API schema at the /rest/v1/ endpoint
CREATE OR REPLACE FUNCTION pg_rest_root() RETURNS JSON AS $_$
DECLARE
openapi JSON = $${"swagger": "2.0","info":{"title":"Private API","description":"This is not a public API. Stop snooping."}}$$;
BEGIN
RETURN openapi;
END
$_$ LANGUAGE plpgsql IMMUTABLE PARALLEL SAFE SET search_path = '';

COMMENT ON FUNCTION pg_rest_root() IS 'Hide the OpenAPI schema for the /rest/v1/ endpoint.';

ALTER ROLE authenticator SET pgrst.db_root_spec = 'public.pg_rest_root';
NOTIFY pgrst, 'reload config';

Did you find this page helpful?