Skip to content

Commit b29614c

Browse files
fix(send-email-link): use X-Meta-Schema for platform data queries
## Problem send-email-link fails for newly provisioned databases (e.g., kanban, crm) with the error: Cannot query field "databases" on type "Query" However, it works correctly for the `constructive` database. ## Root Cause send-email-link queries platform-level data (databases, sites, domains, siteThemes, siteModules) using `X-Api-Name: private` header. This relies on the database's `private` API having access to meta schemas. The issue is: - `constructive` database: private API includes meta schemas (seed data) - New databases (kanban, crm): private API does NOT include meta schemas The `private` API's accessible schemas are determined by the `services_public.api_schemas` table. For `constructive`, this was manually configured to include `metaschema_public` and `services_public`. But the provision flow does not add these meta schemas for new databases. ## Analysis GetDatabaseInfo query needs: - `databases` table (metaschema_public) - `sites`, `domains`, `siteThemes`, `siteModules` tables (services_public) These are platform-level data, not per-database business data. They should be accessed via `X-Meta-Schema: true` header, which directly exposes the meta schemas regardless of which database is being queried. ## Solution Change the `meta` GraphQL client to use `useMetaSchema: true` instead of `X-Api-Name: private`. This ensures: 1. Platform data is always accessible via X-Meta-Schema header 2. No dependency on per-database API configuration 3. Works for all databases (existing and new) The `client` (for GetUser query) still uses `X-Api-Name: private` since it needs per-database user data. ## Before ```typescript const meta = createGraphQLClient(metaGraphqlUrl, { databaseId, ...(apiName && { apiName }), // X-Api-Name: private }); ``` ## After ```typescript const meta = createGraphQLClient(metaGraphqlUrl, { useMetaSchema: true, // X-Meta-Schema: true }); ``` ## Testing Verified with: - constructive database: ✅ email sent successfully - kanban database: ✅ email sent successfully (was failing before)
1 parent c18ef8e commit b29614c

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

functions/send-email-link/src/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,11 @@ app.post('/', async (req: any, res: any, next: any) => {
361361
...(schemata && { schemata }),
362362
});
363363

364-
// For GetDatabaseInfo query - uses same API routing as client
365-
// The private API exposes both user and database queries
364+
// For GetDatabaseInfo query - uses X-Meta-Schema to access platform data
365+
// (databases, sites, domains, siteThemes, siteModules are platform-level data)
366366
const meta = createGraphQLClient(metaGraphqlUrl, {
367367
hostHeaderEnvVar: 'META_GRAPHQL_HOST_HEADER',
368-
databaseId,
369-
...(apiName && { apiName }),
370-
...(schemata && { schemata }),
368+
useMetaSchema: true,
371369
});
372370

373371
const result = await sendEmailLink(params, {

0 commit comments

Comments
 (0)