-- Canonical Party: API surface (runs on the ods service). -- -- PostgREST connects as `authenticator` and switches to the platform's `anon` role, so the -- GraphQL API sees exactly what `anon` is granted here. The lab has no authentication; a real -- deployment would grant per-consumer roles and add row-level security policies. GRANT USAGE ON SCHEMA canonical_party TO anon; GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA canonical_party TO anon; GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA canonical_party TO anon; ALTER DEFAULT PRIVILEGES IN SCHEMA canonical_party GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO anon; -- The product's GraphQL endpoint: POST /rpc/canonical_party_graphql through PostgREST. -- pg_graphql reflects the schemas on the search_path, so the SET clause is what scopes this -- endpoint to the product's tables and keeps other products out of its schema. CREATE FUNCTION api.canonical_party_graphql( query text, variables jsonb DEFAULT '{}'::jsonb, "operationName" text DEFAULT NULL, extensions jsonb DEFAULT NULL ) RETURNS jsonb LANGUAGE sql SECURITY INVOKER SET search_path = canonical_party, graphql AS $$ SELECT graphql.resolve(query, variables, "operationName", extensions); $$; GRANT EXECUTE ON FUNCTION api.canonical_party_graphql(text, jsonb, text, jsonb) TO anon; -- PostgREST caches the API definition; ask it to pick up the new endpoint. NOTIFY pgrst, 'reload schema';