From 8b138de59638546c65c6566b728622bb50e658ee Mon Sep 17 00:00:00 2001 From: Dan Lynch Date: Sun, 25 May 2025 13:18:48 -0700 Subject: [PATCH 1/6] TS cleanup --- packages/server/src/middleware/api.ts | 12 ++++-------- packages/server/src/middleware/auth.ts | 1 - 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/server/src/middleware/api.ts b/packages/server/src/middleware/api.ts index 80c28e0cc..c315a472c 100644 --- a/packages/server/src/middleware/api.ts +++ b/packages/server/src/middleware/api.ts @@ -75,10 +75,8 @@ const getHardCodedSchemata = ({ .map((schema) => schema.trim()) .map((schemaName) => ({ schemaName })) }, - // @ts-ignore - schemaNames: { nodes: [] }, - // @ts-ignore - apiModules: { nodes: [] } + schemaNames: { nodes: [] as Array<{ schemaName: string }> }, + apiModules: { nodes: [] as Array } } } }; @@ -107,10 +105,8 @@ const getMetaSchema = ({ schemaNamesFromExt: { nodes: schemata.map((schemaName: string) => ({ schemaName })) }, - // @ts-ignore - schemaNames: { nodes: [] }, - // @ts-ignore - apiModules: { nodes: [] } + schemaNames: { nodes: [] as Array<{ schemaName: string }> }, + apiModules: { nodes: [] as Array } } } }; diff --git a/packages/server/src/middleware/auth.ts b/packages/server/src/middleware/auth.ts index b2b4ed9eb..ed33d5a09 100644 --- a/packages/server/src/middleware/auth.ts +++ b/packages/server/src/middleware/auth.ts @@ -72,7 +72,6 @@ export const createAuthenticateMiddleware = (opts: LaunchQLOptions): RequestHand } } - // @ts-ignore - augment req with `token` req.token = token; } From 8bcc534580ff8fa35ce9f018018adcb55b57f462 Mon Sep 17 00:00:00 2001 From: Dan Lynch Date: Sun, 25 May 2025 13:19:49 -0700 Subject: [PATCH 2/6] meta API abs --- packages/cli/src/commands/server.ts | 41 +++++++++++++- packages/server/src/errors/50x.ts | 3 +- packages/server/src/index.ts | 3 +- packages/server/src/middleware/api.ts | 2 +- .../server/src/middleware/directSchema.ts | 45 ++++++++++++++++ packages/server/src/middleware/graphile.ts | 23 ++++++-- packages/server/src/server.ts | 54 +++++++++++++++---- packages/types/src/env.ts | 23 ++++++++ packages/types/src/launchql.ts | 19 ++++++- 9 files changed, 190 insertions(+), 23 deletions(-) create mode 100644 packages/server/src/middleware/directSchema.ts diff --git a/packages/cli/src/commands/server.ts b/packages/cli/src/commands/server.ts index 0b992d29f..c08673387 100644 --- a/packages/cli/src/commands/server.ts +++ b/packages/cli/src/commands/server.ts @@ -37,7 +37,32 @@ const questions: Question[] = [ required: false, default: 5555, useDefault: true + }, + { + name: 'useMetaApi', + message: 'Use Meta API for schema discovery?', + type: 'confirm', + required: false, + default: true, + useDefault: true + }, + { + name: 'schemas', + message: 'Schemas to expose (comma-separated, only if not using Meta API)', + type: 'text', + required: false, + dependsOn: ['useMetaApi'], + when: (answers: any) => !answers.useMetaApi } +// { +// name: 'origin', +// message: chalk.cyan('CORS origin URL'), +// type: 'text', +// // alias: 'o', +// required: false, +// default: 'http://localhost:3000', +// useDefault: true +// } ]; export default async ( @@ -77,7 +102,9 @@ export default async ( oppositeBaseNames, port, postgis, - simpleInflection + simpleInflection, + useMetaApi, + schemas } = await prompter.prompt(argv, questions); const options: LaunchQLOptions = getEnvOptions({ @@ -88,9 +115,19 @@ export default async ( postgis }, server: { - port + port, + middleware: { + useMetaApi + } } }); + + if (!useMetaApi && schemas) { + options.graphile = { + ...options.graphile, + schema: schemas.split(',').map((s: string) => s.trim()) + }; + } log.success('✅ Selected Configuration:'); for (const [key, value] of Object.entries(options)) { diff --git a/packages/server/src/errors/50x.ts b/packages/server/src/errors/50x.ts index a20d389a8..eb88ee817 100644 --- a/packages/server/src/errors/50x.ts +++ b/packages/server/src/errors/50x.ts @@ -1,4 +1,4 @@ -export default ` +export default (code: string) => ` @@ -205,6 +205,7 @@ export default `

Uh Oh!

We’re really sorry about that. Please contact support of the issue persists.

+

code: ${code}

diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index 7e59ff5d1..7f0dd2061 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -1 +1,2 @@ -export * from './server'; \ No newline at end of file +export * from './server'; +export * from './middleware/directSchema'; diff --git a/packages/server/src/middleware/api.ts b/packages/server/src/middleware/api.ts index c315a472c..46f295a4b 100644 --- a/packages/server/src/middleware/api.ts +++ b/packages/server/src/middleware/api.ts @@ -44,7 +44,7 @@ export const createApiMiddleware = (opts: LaunchQLOptions) => { res.status(404).send(errorPage404Message('The resource you’re looking for does not exist.')); } else { console.error(e); - res.status(500).send(errorPage50x); + res.status(500).send(errorPage50x('API Error')); } } }; diff --git a/packages/server/src/middleware/directSchema.ts b/packages/server/src/middleware/directSchema.ts new file mode 100644 index 000000000..abbd4d778 --- /dev/null +++ b/packages/server/src/middleware/directSchema.ts @@ -0,0 +1,45 @@ +import { LaunchQLOptions } from '@launchql/types'; +import { Response, NextFunction } from 'express'; +import errorPage404 from '../errors/404-message'; +import errorPage50x from '../errors/50x'; + +export const createDirectSchemaMiddleware = (opts: LaunchQLOptions) => { + return async (req: any, res: Response, next: NextFunction): Promise => { + try { + const schemas = opts.graphile?.schema || []; + const schemaArray = Array.isArray(schemas) ? schemas : [schemas]; + + if (!schemaArray.length) { + res.status(404).send(errorPage404('no schema for hard-coded schema')); + return; + } + + const svc = { + data: { + api: { + databaseId: 'direct-schema', + isPublic: opts.graphile.isPublic, + dbname: opts.pg.database, + anonRole: 'anonymous', + roleName: 'administrator', + schemaNamesFromExt: { + nodes: schemaArray.map(schemaName => ({ schemaName })) + }, + schemaNames: { nodes: [] as Array<{ schemaName: string }> }, + apiModules: { nodes: [] as Array } + } + } + }; + + req.apiInfo = svc; + req.databaseId = svc.data.api.databaseId; + req.svc_key = 'direct-schema'; + + next(); + } catch (e: any) { + console.error(e); + res.status(500).send(errorPage50x('directSchema')); + return; + } + }; +}; diff --git a/packages/server/src/middleware/graphile.ts b/packages/server/src/middleware/graphile.ts index 816516cfe..c96c0000a 100644 --- a/packages/server/src/middleware/graphile.ts +++ b/packages/server/src/middleware/graphile.ts @@ -14,11 +14,22 @@ export const graphile = (lOpts: LaunchQLOptions): RequestHandler => { const key = req.svc_key; const { dbname } = api; const { anonRole, roleName } = api; - - const { schemaNamesFromExt, schemaNames } = api; - const schemas = [] - .concat(schemaNamesFromExt.nodes.map(({ schemaName }: any) => schemaName)) - .concat(schemaNames.nodes.map(({ schemaName }: any) => schemaName)); + + let schemas = [] as Array<{ schemaName: string }> + + if (api.schemaNamesFromExt && api.schemaNamesFromExt.nodes) { + schemas = schemas.concat(api.schemaNamesFromExt.nodes.map(({ schemaName }: any) => schemaName)); + } + + if (api.schemaNames && api.schemaNames.nodes) { + schemas = schemas.concat(api.schemaNames.nodes.map(({ schemaName }: any) => schemaName)); + } + + if (schemas.length === 0 && lOpts.graphile?.schema) { + const directSchemas = lOpts.graphile.schema; + // @ts-ignore + schemas = Array.isArray(directSchemas) ? directSchemas : [directSchemas]; + } if (graphileCache.has(key)) { const { handler } = graphileCache.get(key)! @@ -29,6 +40,7 @@ export const graphile = (lOpts: LaunchQLOptions): RequestHandler => { ...lOpts, graphile: { ...lOpts.graphile, + // @ts-ignore schema: schemas } }); @@ -87,6 +99,7 @@ export const graphile = (lOpts: LaunchQLOptions): RequestHandler => { ...lOpts.pg, database: dbname }); + // @ts-ignore const handler = postgraphile(pgPool, schemas, opts); graphileCache.set(key, { diff --git a/packages/server/src/server.ts b/packages/server/src/server.ts index 1fb365fa1..964532ad0 100644 --- a/packages/server/src/server.ts +++ b/packages/server/src/server.ts @@ -12,6 +12,7 @@ import { createAuthenticateMiddleware } from './middleware/auth'; import { graphile } from './middleware/graphile'; import { cors } from './middleware/cors'; import { createApiMiddleware } from './middleware/api'; +import { createDirectSchemaMiddleware } from './middleware/directSchema'; import { flush, flushService } from './middleware/flush'; import requestIp from 'request-ip'; import { Pool, PoolClient } from 'pg'; @@ -33,25 +34,56 @@ class Server { constructor(opts: LaunchQLOptions) { this.opts = opts; - + const app = express(); - const api = createApiMiddleware(opts); - const authenticate = createAuthenticateMiddleware(opts); - + healthz(app); - trustProxy(app, opts.server.trustProxy); + trustProxy(app, opts.server?.trustProxy); app.use(poweredBy('launchql')); app.use(graphqlUploadExpress()); app.use(parseDomains() as RequestHandler); app.use(requestIp.mw()); - app.use(api); - app.use(cors as any); - app.use(authenticate); - app.use(graphile(opts)); - app.use(flush); - + + this.registerMiddleware(app); + this.app = app; } + + private registerMiddleware(app: Express): void { + const middlewareOpts = this.opts.server?.middleware || {}; + + if (middlewareOpts.useMetaApi !== false) { + const api = createApiMiddleware(this.opts); + app.use(api); + } else { + const directSchema = createDirectSchemaMiddleware(this.opts); + app.use(directSchema); + } + + if (middlewareOpts.useCors !== false) { + app.use(cors as any); + } + + if (middlewareOpts.useAuth !== false) { + const authenticate = createAuthenticateMiddleware(this.opts); + app.use(authenticate); + } + + if (middlewareOpts.useGraphile !== false) { + const graphileMiddleware = graphile(this.opts); + app.use(graphileMiddleware); + } + + if (middlewareOpts.useFlush !== false) { + app.use(flush); + } + + if (Array.isArray(middlewareOpts.customMiddleware)) { + middlewareOpts.customMiddleware.forEach((middleware, index) => { + app.use(middleware); + }); + } + } listen(): void { const { server } = this.opts; diff --git a/packages/types/src/env.ts b/packages/types/src/env.ts index 07db7467b..a56aaf7aa 100644 --- a/packages/types/src/env.ts +++ b/packages/types/src/env.ts @@ -43,6 +43,12 @@ const getEnvVars = (): LaunchQLOptions => { SERVER_TRUST_PROXY, SERVER_ORIGIN, SERVER_STRICT_AUTH, + + SERVER_MIDDLEWARE_USE_META_API, + SERVER_MIDDLEWARE_USE_AUTH, + SERVER_MIDDLEWARE_USE_CORS, + SERVER_MIDDLEWARE_USE_GRAPHILE, + SERVER_MIDDLEWARE_USE_FLUSH, PGHOST, PGPORT, @@ -71,6 +77,23 @@ const getEnvVars = (): LaunchQLOptions => { ...(SERVER_TRUST_PROXY && { trustProxy: parseEnvBoolean(SERVER_TRUST_PROXY) }), ...(SERVER_ORIGIN && { origin: SERVER_ORIGIN }), ...(SERVER_STRICT_AUTH && { strictAuth: parseEnvBoolean(SERVER_STRICT_AUTH) }), + middleware: { + ...(SERVER_MIDDLEWARE_USE_META_API !== undefined && { + useMetaApi: parseEnvBoolean(SERVER_MIDDLEWARE_USE_META_API) + }), + ...(SERVER_MIDDLEWARE_USE_AUTH !== undefined && { + useAuth: parseEnvBoolean(SERVER_MIDDLEWARE_USE_AUTH) + }), + ...(SERVER_MIDDLEWARE_USE_CORS !== undefined && { + useCors: parseEnvBoolean(SERVER_MIDDLEWARE_USE_CORS) + }), + ...(SERVER_MIDDLEWARE_USE_GRAPHILE !== undefined && { + useGraphile: parseEnvBoolean(SERVER_MIDDLEWARE_USE_GRAPHILE) + }), + ...(SERVER_MIDDLEWARE_USE_FLUSH !== undefined && { + useFlush: parseEnvBoolean(SERVER_MIDDLEWARE_USE_FLUSH) + }), + }, }, pg: { ...(PGHOST && { host: PGHOST }), diff --git a/packages/types/src/launchql.ts b/packages/types/src/launchql.ts index 0219a18de..7341e81fa 100644 --- a/packages/types/src/launchql.ts +++ b/packages/types/src/launchql.ts @@ -80,6 +80,14 @@ export interface LaunchQLOptions { trustProxy?: boolean; origin?: string; strictAuth?: boolean; + middleware?: { + useMetaApi?: boolean; + useAuth?: boolean; + useCors?: boolean; + useGraphile?: boolean; + useFlush?: boolean; + customMiddleware?: any[]; + }; }; features?: { simpleInflection?: boolean; @@ -118,8 +126,7 @@ export const launchqlDefaults: LaunchQLOptions = { graphile: { isPublic: true, schema: ['public'], - // TODO how to handle metaSchemas...? - metaSchemas: ['collections_public', 'meta_public'], + metaSchemas: ['meta_public'], appendPlugins: [], overrideSettings: {}, graphileBuildOptions: {}, @@ -129,6 +136,14 @@ export const launchqlDefaults: LaunchQLOptions = { port: 3000, trustProxy: false, strictAuth: false, + middleware: { + useMetaApi: true, + useAuth: true, + useCors: true, + useGraphile: true, + useFlush: true, + customMiddleware: [] + } }, features: { simpleInflection: true, From f9e93337ccba84f0d2efd48fa5dafa5917f2e380 Mon Sep 17 00:00:00 2001 From: Dan Lynch Date: Sun, 25 May 2025 13:26:42 -0700 Subject: [PATCH 3/6] we need to have collections_public and meta_public for things to work --- packages/types/src/launchql.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/types/src/launchql.ts b/packages/types/src/launchql.ts index 7341e81fa..b6d1ade62 100644 --- a/packages/types/src/launchql.ts +++ b/packages/types/src/launchql.ts @@ -126,7 +126,8 @@ export const launchqlDefaults: LaunchQLOptions = { graphile: { isPublic: true, schema: ['public'], - metaSchemas: ['meta_public'], + // meta has a ref to databaseId, hence the connection here... + metaSchemas: ['collections_public', 'meta_public'], appendPlugins: [], overrideSettings: {}, graphileBuildOptions: {}, From 9e27ab63a86ce399f206c87918abfc251fce1b4e Mon Sep 17 00:00:00 2001 From: Dan Lynch Date: Mon, 26 May 2025 17:31:01 -0700 Subject: [PATCH 4/6] updates --- packages/cli/src/commands/export.ts | 5 ++++- packages/core/src/class/launchql.ts | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/commands/export.ts b/packages/cli/src/commands/export.ts index 8d182177d..95dd0cf96 100644 --- a/packages/cli/src/commands/export.ts +++ b/packages/cli/src/commands/export.ts @@ -14,6 +14,7 @@ export default async ( const project = new LaunchQLProject(cwd); project.ensureWorkspace(); + project.resetCwd(project.workspacePath); const options = getEnvOptions(); @@ -105,13 +106,15 @@ export default async ( } ]); + const outdir = resolve(project.workspacePath, 'packages/'); + await exportMigrations({ project, options, dbInfo, author, schema_names, - outdir: resolve(project.workspacePath, 'packages/'), + outdir, extensionName, metaExtensionName }); diff --git a/packages/core/src/class/launchql.ts b/packages/core/src/class/launchql.ts index 0184e18dd..9bbfa9d03 100644 --- a/packages/core/src/class/launchql.ts +++ b/packages/core/src/class/launchql.ts @@ -71,7 +71,7 @@ export interface InitModuleOptions { } export class LaunchQLProject { - public readonly cwd: string; + public cwd: string; public workspacePath?: string; public modulePath?: string; public config?: any; @@ -81,7 +81,11 @@ export class LaunchQLProject { private _moduleInfo?: ExtensionInfo; constructor(cwd: string = process.cwd()) { - this.cwd = path.resolve(cwd); + this.resetCwd(cwd); + } + + resetCwd(cwd: string) { + this.cwd = cwd; this.workspacePath = this.resolveLaunchqlPath(); this.modulePath = this.resolveSqitchPath(); From 497015501b735c6dde0d5557ead3aca6f764f375 Mon Sep 17 00:00:00 2001 From: Dan Lynch Date: Mon, 26 May 2025 17:57:48 -0700 Subject: [PATCH 5/6] direct is for admin --- packages/cli/src/commands/server.ts | 59 +++++++++++-------- .../server/src/middleware/directSchema.ts | 7 ++- packages/types/src/launchql.ts | 2 +- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/packages/cli/src/commands/server.ts b/packages/cli/src/commands/server.ts index c08673387..ac3935745 100644 --- a/packages/cli/src/commands/server.ts +++ b/packages/cli/src/commands/server.ts @@ -1,11 +1,11 @@ import { LaunchQLServer as server } from '@launchql/server'; -import { CLIOptions, Inquirerer, Question } from 'inquirerer'; +import { CLIOptions, Inquirerer, OptionValue, Question } from 'inquirerer'; import { getEnvOptions, LaunchQLOptions } from '@launchql/types'; import { getRootPgPool, Logger } from '@launchql/server-utils'; const log = new Logger('server'); -const questions: Question[] = [ +const initialQuestions: Question[] = [ { name: 'simpleInflection', message: 'Use simple inflection?', @@ -45,24 +45,7 @@ const questions: Question[] = [ required: false, default: true, useDefault: true - }, - { - name: 'schemas', - message: 'Schemas to expose (comma-separated, only if not using Meta API)', - type: 'text', - required: false, - dependsOn: ['useMetaApi'], - when: (answers: any) => !answers.useMetaApi } -// { -// name: 'origin', -// message: chalk.cyan('CORS origin URL'), -// type: 'text', -// // alias: 'o', -// required: false, -// default: 'http://localhost:3000', -// useDefault: true -// } ]; export default async ( @@ -103,9 +86,35 @@ export default async ( port, postgis, simpleInflection, - useMetaApi, - schemas - } = await prompter.prompt(argv, questions); + useMetaApi + } = await prompter.prompt(argv, initialQuestions); + + let selectedSchemas: string[] = []; + + if (!useMetaApi) { + const appDb = await getRootPgPool({ database: selectedDb }); + const result = await appDb.query(` + SELECT nspname AS schema_name + FROM pg_namespace + WHERE nspname NOT LIKE 'pg_%' + AND nspname != 'information_schema' + ORDER BY nspname; + `); + + const availableSchemas = result.rows.map(row => row.schema_name); + + const { schemas } = await prompter.prompt(argv, [ + { + name: 'schemas', + message: 'Select schemas to expose', + type: 'checkbox', + options: availableSchemas, + required: true + } + ]); + + selectedSchemas = schemas.filter((s:OptionValue)=>s.selected).map((s:OptionValue)=>s.value); + } const options: LaunchQLOptions = getEnvOptions({ pg: { database: selectedDb }, @@ -121,11 +130,11 @@ export default async ( } } }); - - if (!useMetaApi && schemas) { + + if (!useMetaApi && selectedSchemas.length > 0) { options.graphile = { ...options.graphile, - schema: schemas.split(',').map((s: string) => s.trim()) + schema: selectedSchemas }; } diff --git a/packages/server/src/middleware/directSchema.ts b/packages/server/src/middleware/directSchema.ts index abbd4d778..7a98ad084 100644 --- a/packages/server/src/middleware/directSchema.ts +++ b/packages/server/src/middleware/directSchema.ts @@ -14,14 +14,17 @@ export const createDirectSchemaMiddleware = (opts: LaunchQLOptions) => { return; } + // let's just pass this in from the CLI when it's needed const svc = { data: { api: { databaseId: 'direct-schema', isPublic: opts.graphile.isPublic, dbname: opts.pg.database, - anonRole: 'anonymous', - roleName: 'administrator', + + // TODO: allow these to be passed in when useMetaApi is off... + anonRole: 'postgres', + roleName: 'postgres', schemaNamesFromExt: { nodes: schemaArray.map(schemaName => ({ schemaName })) }, diff --git a/packages/types/src/launchql.ts b/packages/types/src/launchql.ts index b6d1ade62..68f237613 100644 --- a/packages/types/src/launchql.ts +++ b/packages/types/src/launchql.ts @@ -125,7 +125,7 @@ export const launchqlDefaults: LaunchQLOptions = { }, graphile: { isPublic: true, - schema: ['public'], + schema: [], // meta has a ref to databaseId, hence the connection here... metaSchemas: ['collections_public', 'meta_public'], appendPlugins: [], From a7865290e388baa9c8979957c83c08652ba7c814 Mon Sep 17 00:00:00 2001 From: Dan Lynch Date: Mon, 26 May 2025 18:19:04 -0700 Subject: [PATCH 6/6] apis test thing things out --- packages/cli/src/commands/server.ts | 55 ++++++++++++++----- .../server/src/middleware/directSchema.ts | 4 +- packages/types/src/launchql.ts | 9 +++ 3 files changed, 51 insertions(+), 17 deletions(-) diff --git a/packages/cli/src/commands/server.ts b/packages/cli/src/commands/server.ts index ac3935745..6fc051465 100644 --- a/packages/cli/src/commands/server.ts +++ b/packages/cli/src/commands/server.ts @@ -80,7 +80,7 @@ export default async ( selectedDb = database; log.info(`📌 Using database: "${selectedDb}"`); } - + const { oppositeBaseNames, port, @@ -89,6 +89,21 @@ export default async ( useMetaApi } = await prompter.prompt(argv, initialQuestions); + const options: LaunchQLOptions = getEnvOptions({ + pg: { database: selectedDb }, + features: { + oppositeBaseNames, + simpleInflection, + postgis + }, + server: { + port, + middleware: { + useMetaApi + } + } + }); + let selectedSchemas: string[] = []; if (!useMetaApi) { @@ -114,22 +129,32 @@ export default async ( ]); selectedSchemas = schemas.filter((s:OptionValue)=>s.selected).map((s:OptionValue)=>s.value); - } - const options: LaunchQLOptions = getEnvOptions({ - pg: { database: selectedDb }, - features: { - oppositeBaseNames, - simpleInflection, - postgis - }, - server: { - port, - middleware: { - useMetaApi + /// roles + + const { anonRole, roleName } = await prompter.prompt(argv, [ + { + name: 'anonRole', + message: 'Select anonymous role', + type: 'autocomplete', + options: ['postgres', 'anonymous', 'authenticated'], + default: 'anonymous', + required: true + }, + { + name: 'roleName', + message: 'Select default role', + type: 'autocomplete', + options: ['postgres', 'anonymous', 'authenticated'], + default: 'authenticated', + required: true } - } - }); + ]); + + options.graphile.anonRole = anonRole; + options.graphile.roleName = roleName; + + } if (!useMetaApi && selectedSchemas.length > 0) { options.graphile = { diff --git a/packages/server/src/middleware/directSchema.ts b/packages/server/src/middleware/directSchema.ts index 7a98ad084..27ada6166 100644 --- a/packages/server/src/middleware/directSchema.ts +++ b/packages/server/src/middleware/directSchema.ts @@ -23,8 +23,8 @@ export const createDirectSchemaMiddleware = (opts: LaunchQLOptions) => { dbname: opts.pg.database, // TODO: allow these to be passed in when useMetaApi is off... - anonRole: 'postgres', - roleName: 'postgres', + anonRole: opts.graphile.anonRole, + roleName: opts.graphile.roleName, schemaNamesFromExt: { nodes: schemaArray.map(schemaName => ({ schemaName })) }, diff --git a/packages/types/src/launchql.ts b/packages/types/src/launchql.ts index 68f237613..e4c230590 100644 --- a/packages/types/src/launchql.ts +++ b/packages/types/src/launchql.ts @@ -73,6 +73,10 @@ export interface LaunchQLOptions { appendPlugins?: Plugin[]; graphileBuildOptions?: PostGraphileOptions['graphileBuildOptions']; overrideSettings?: Partial; + // Only used when useMetaApi is false + anonRole?: string; + // Only used when useMetaApi is false + roleName?: string; }; server?: { host?: string; @@ -123,6 +127,7 @@ export const launchqlDefaults: LaunchQLOptions = { password: 'password', database: 'postgres', }, + // TODO these should all be subset of postgraphile options since we do spread these when we call getSettings() in server graphile: { isPublic: true, schema: [], @@ -131,6 +136,10 @@ export const launchqlDefaults: LaunchQLOptions = { appendPlugins: [], overrideSettings: {}, graphileBuildOptions: {}, + // Only used when useMetaApi is false + anonRole: 'anonymous', + // Only used when useMetaApi is false + roleName: 'authenticated', }, server: { host: 'localhost',