The canonical data product for the Digital Core domain, copied unchanged from the blog repository's products/canonical-party (generated by /agent-product from data_model/data_products/canonical.md, 65 of 65 checks on the blog's stack on 2026-09-09). The next commit adapts it to the domain platform. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
32 lines
1.4 KiB
PL/PgSQL
32 lines
1.4 KiB
PL/PgSQL
-- Canonical Party: API surface (runs on the postgres 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';
|