Skip to content

Commit 9269815

Browse files
committed
fix(fn-runtime): meta client must use X-Meta-Schema, not X-Api-Name
The meta GraphQLClient created in createClients() is used for queries against platform-level data (databases, sites, domains, themes — tables in metaschema_public). It should NOT use tenant API routing. Sending X-Api-Name: <name> causes the server to look up every schema registered for that API in services_public.api_schemas. The 'private' API in particular is registered (per metaschema_generators.provision_database_apis) with both the *_public and *_private variants of every module schema. graphile-build-pg then tries to introspect all of them, finds tables that exist under the same name in two schemas (e.g. identity_providers in both constructive_auth_public and constructive_auth_private), and fails the schema build with: Error: Attempted to add a second codec named 'identityProviders' (existing: RecordCodec(identityProviders), new: RecordCodec(identityProviders)) After the schema build fails, every request to that server returns a 500 'Unknown error occurred', so functions calling GetDatabaseInfo via the meta client get back nothing usable. The correct routing for platform data is X-Meta-Schema: true, which takes the schema list from API_META_SCHEMAS env var rather than querying the DB. This matches the routing the older in-monorepo implementation used (see constructive/functions/send-email-link/src/index.ts on the constructive repo). The detail was lost during the extraction into this repo. Bug present since the initial setup commit (272763a, 2026-02-11) but not exercised until consumers (e.g. constructive-hub) started loading this fn-runtime instead of the in-monorepo function.
1 parent c0ebc1c commit 9269815

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

packages/fn-runtime/src/graphql.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,14 @@ export const createClients = (
6161
...(schemata && { schemata })
6262
});
6363

64+
// Meta client targets platform-level data (databases, sites, domains, themes
65+
// in metaschema_public). It must NOT use tenant API routing — sending
66+
// X-Api-Name causes the server to load every schema registered for that API
67+
// (both *_public and *_private variants), which collides on duplicate codec
68+
// names like identityProviders. Use X-Meta-Schema instead.
6469
const meta = createGraphQLClient(metaGraphqlUrl, env, {
6570
hostHeaderEnvVar: 'META_GRAPHQL_HOST_HEADER',
66-
databaseId,
67-
...(apiName && { apiName }),
68-
...(schemata && { schemata })
71+
useMetaSchema: true,
6972
});
7073

7174
return { client, meta };

0 commit comments

Comments
 (0)