@@ -28,8 +28,16 @@ export interface ConfigOverrideOptions {
2828 schema ?: string ;
2929 /** Database name or connection string (for database introspection) */
3030 database ?: string ;
31- /** PostgreSQL schemas to include (for database mode) */
31+ /** Path to a PGPM module directory (for module introspection) */
32+ pgpmModulePath ?: string ;
33+ /** Path to a PGPM workspace directory (used with pgpmModuleName) */
34+ pgpmWorkspacePath ?: string ;
35+ /** Name of the module within the workspace (used with pgpmWorkspacePath) */
36+ pgpmModuleName ?: string ;
37+ /** PostgreSQL schemas to include (for database and pgpm module modes) */
3238 schemas ?: string [ ] ;
39+ /** Keep the ephemeral database after introspection (for debugging, pgpm module mode only) */
40+ keepDb ?: boolean ;
3341 /** Output directory (overrides config) */
3442 output ?: string ;
3543}
@@ -44,31 +52,74 @@ export interface LoadConfigResult {
4452 error ?: string ;
4553}
4654
55+ /**
56+ * Extended overrides type that includes database and PGPM module options
57+ */
58+ export interface ExtendedTargetOverrides extends GraphQLSDKConfigTarget {
59+ database ?: string ;
60+ schemas ?: string [ ] ;
61+ pgpmModulePath ?: string ;
62+ pgpmWorkspacePath ?: string ;
63+ pgpmModuleName ?: string ;
64+ keepDb ?: boolean ;
65+ }
66+
4767/**
4868 * Build target overrides from options
4969 */
5070export function buildTargetOverrides (
5171 options : ConfigOverrideOptions
52- ) : GraphQLSDKConfigTarget & { database ?: string ; schemas ?: string [ ] } {
53- const overrides : GraphQLSDKConfigTarget & { database ?: string ; schemas ?: string [ ] } = { } ;
72+ ) : ExtendedTargetOverrides {
73+ const overrides : ExtendedTargetOverrides = { } ;
5474
5575 if ( options . endpoint ) {
5676 overrides . endpoint = options . endpoint ;
5777 overrides . schema = undefined ;
5878 overrides . database = undefined ;
79+ overrides . pgpmModulePath = undefined ;
80+ overrides . pgpmWorkspacePath = undefined ;
81+ overrides . pgpmModuleName = undefined ;
5982 }
6083
6184 if ( options . schema ) {
6285 overrides . schema = options . schema ;
6386 overrides . endpoint = undefined ;
6487 overrides . database = undefined ;
88+ overrides . pgpmModulePath = undefined ;
89+ overrides . pgpmWorkspacePath = undefined ;
90+ overrides . pgpmModuleName = undefined ;
6591 }
6692
6793 if ( options . database ) {
6894 overrides . database = options . database ;
6995 overrides . schemas = options . schemas ;
7096 overrides . endpoint = undefined ;
7197 overrides . schema = undefined ;
98+ overrides . pgpmModulePath = undefined ;
99+ overrides . pgpmWorkspacePath = undefined ;
100+ overrides . pgpmModuleName = undefined ;
101+ }
102+
103+ if ( options . pgpmModulePath ) {
104+ overrides . pgpmModulePath = options . pgpmModulePath ;
105+ overrides . schemas = options . schemas ;
106+ overrides . keepDb = options . keepDb ;
107+ overrides . endpoint = undefined ;
108+ overrides . schema = undefined ;
109+ overrides . database = undefined ;
110+ overrides . pgpmWorkspacePath = undefined ;
111+ overrides . pgpmModuleName = undefined ;
112+ }
113+
114+ if ( options . pgpmWorkspacePath && options . pgpmModuleName ) {
115+ overrides . pgpmWorkspacePath = options . pgpmWorkspacePath ;
116+ overrides . pgpmModuleName = options . pgpmModuleName ;
117+ overrides . schemas = options . schemas ;
118+ overrides . keepDb = options . keepDb ;
119+ overrides . endpoint = undefined ;
120+ overrides . schema = undefined ;
121+ overrides . database = undefined ;
122+ overrides . pgpmModulePath = undefined ;
72123 }
73124
74125 if ( options . output ) {
@@ -90,12 +141,22 @@ export function buildTargetOverrides(
90141export async function loadAndResolveConfig (
91142 options : ConfigOverrideOptions
92143) : Promise < LoadConfigResult > {
144+ // Check for pgpm workspace mode (requires both pgpmWorkspacePath and pgpmModuleName)
145+ const hasPgpmWorkspace = options . pgpmWorkspacePath && options . pgpmModuleName ;
146+
93147 // Validate that at most one source is specified
94- const sources = [ options . endpoint , options . schema , options . database ] . filter ( Boolean ) ;
148+ const sources = [
149+ options . endpoint ,
150+ options . schema ,
151+ options . database ,
152+ options . pgpmModulePath ,
153+ hasPgpmWorkspace ,
154+ ] . filter ( Boolean ) ;
95155 if ( sources . length > 1 ) {
96156 return {
97157 success : false ,
98- error : 'Multiple sources specified. Use only one of: endpoint, schema, or database.' ,
158+ error :
159+ 'Multiple sources specified. Use only one of: endpoint, schema, database, pgpmModulePath, or pgpmWorkspacePath + pgpmModuleName.' ,
99160 } ;
100161 }
101162
@@ -195,7 +256,7 @@ function resolveMultiTargetConfig(
195256function resolveSingleTargetConfig (
196257 baseConfig : GraphQLSDKConfigTarget ,
197258 options : ConfigOverrideOptions ,
198- overrides : GraphQLSDKConfigTarget
259+ overrides : ExtendedTargetOverrides
199260) : LoadConfigResult {
200261 if ( options . target ) {
201262 return {
@@ -207,23 +268,42 @@ function resolveSingleTargetConfig(
207268
208269 const mergedConfig = mergeConfig ( baseConfig , overrides ) ;
209270
210- // Check if we have a source (endpoint, schema, or database)
211- const hasSource = mergedConfig . endpoint || mergedConfig . schema || ( overrides as any ) . database ;
271+ // Check if we have a source (endpoint, schema, database, or pgpm module)
272+ const hasSource =
273+ mergedConfig . endpoint ||
274+ mergedConfig . schema ||
275+ overrides . database ||
276+ overrides . pgpmModulePath ||
277+ ( overrides . pgpmWorkspacePath && overrides . pgpmModuleName ) ;
278+
212279 if ( ! hasSource ) {
213280 return {
214281 success : false ,
215282 error :
216- 'No source specified. Use --endpoint, --schema, or --database , or create a config file with "graphql-codegen init".' ,
283+ 'No source specified. Use --endpoint, --schema, --database, --pgpmModulePath, or --pgpmWorkspacePath + --pgpmModuleName , or create a config file with "graphql-codegen init".' ,
217284 } ;
218285 }
219286
220287 // For database mode, we need to pass the database info through to the resolved config
221288 const resolvedConfig = resolveConfig ( mergedConfig ) ;
222-
223- // Attach database options if present (they're not part of the standard config type)
224- if ( ( overrides as any ) . database ) {
225- ( resolvedConfig as any ) . database = ( overrides as any ) . database ;
226- ( resolvedConfig as any ) . schemas = ( overrides as any ) . schemas ;
289+
290+ // Attach extended options if present (they're not part of the standard config type)
291+ if ( overrides . database ) {
292+ ( resolvedConfig as any ) . database = overrides . database ;
293+ ( resolvedConfig as any ) . schemas = overrides . schemas ;
294+ }
295+
296+ if ( overrides . pgpmModulePath ) {
297+ ( resolvedConfig as any ) . pgpmModulePath = overrides . pgpmModulePath ;
298+ ( resolvedConfig as any ) . schemas = overrides . schemas ;
299+ ( resolvedConfig as any ) . keepDb = overrides . keepDb ;
300+ }
301+
302+ if ( overrides . pgpmWorkspacePath && overrides . pgpmModuleName ) {
303+ ( resolvedConfig as any ) . pgpmWorkspacePath = overrides . pgpmWorkspacePath ;
304+ ( resolvedConfig as any ) . pgpmModuleName = overrides . pgpmModuleName ;
305+ ( resolvedConfig as any ) . schemas = overrides . schemas ;
306+ ( resolvedConfig as any ) . keepDb = overrides . keepDb ;
227307 }
228308
229309 return {
0 commit comments