@@ -14,7 +14,7 @@ import { pgCache } from 'pg-cache';
1414import { createEphemeralDb , type EphemeralDbResult } from 'pgsql-client' ;
1515import { deployPgpm } from 'pgsql-seed' ;
1616
17- import type { CliConfig , DbConfig , GraphQLSDKConfigTarget , PgpmConfig } from '../types/config' ;
17+ import type { CliConfig , DbConfig , GraphQLSDKConfigTarget , PgpmConfig , SchemaConfig } from '../types/config' ;
1818import { getConfigOptions } from '../types/config' ;
1919import type { CleanOperation , CleanTable , TypeRegistry } from '../types/schema' ;
2020import { generate as generateReactQueryFiles } from './codegen' ;
@@ -64,9 +64,6 @@ export interface GenerateOptions extends GraphQLSDKConfigTarget {
6464 verbose ?: boolean ;
6565 dryRun ?: boolean ;
6666 skipCustomOperations ?: boolean ;
67- schemaOnly ?: boolean ;
68- schemaOnlyOutput ?: string ;
69- schemaOnlyFilename ?: string ;
7067}
7168
7269export interface GenerateResult {
@@ -140,7 +137,9 @@ export async function generate(
140137 options . nodeHttpAdapter === true ||
141138 ( runCli && options . nodeHttpAdapter !== false ) ;
142139
143- if ( ! options . schemaOnly && ! runReactQuery && ! runOrm && ! runCli ) {
140+ const schemaEnabled = ! ! options . schema ?. enabled ;
141+
142+ if ( ! schemaEnabled && ! runReactQuery && ! runOrm && ! runCli ) {
144143 return {
145144 success : false ,
146145 message :
@@ -171,7 +170,7 @@ export async function generate(
171170 headers : config . headers ,
172171 } ) ;
173172
174- if ( options . schemaOnly ) {
173+ if ( schemaEnabled && ! runReactQuery && ! runOrm && ! runCli ) {
175174 try {
176175 console . log ( `Fetching schema from ${ source . describe ( ) } ...` ) ;
177176 const { introspection } = await source . fetch ( ) ;
@@ -186,9 +185,9 @@ export async function generate(
186185 } ;
187186 }
188187
189- const outDir = path . resolve ( options . schemaOnlyOutput || outputRoot || '.' ) ;
188+ const outDir = path . resolve ( options . schema ?. output || outputRoot || '.' ) ;
190189 await fs . promises . mkdir ( outDir , { recursive : true } ) ;
191- const filename = options . schemaOnlyFilename || 'schema.graphql' ;
190+ const filename = options . schema ?. filename || 'schema.graphql' ;
192191 const filePath = path . join ( outDir , filename ) ;
193192 await fs . promises . writeFile ( filePath , sdl , 'utf-8' ) ;
194193
@@ -550,7 +549,7 @@ export interface GenerateMultiOptions {
550549 cliOverrides ?: Partial < GraphQLSDKConfigTarget > ;
551550 verbose ?: boolean ;
552551 dryRun ?: boolean ;
553- schemaOnly ?: boolean ;
552+ schema ?: SchemaConfig ;
554553 unifiedCli ?: CliConfig | boolean ;
555554}
556555
@@ -669,13 +668,14 @@ function applySharedPgpmDb(
669668export async function generateMulti (
670669 options : GenerateMultiOptions ,
671670) : Promise < GenerateMultiResult > {
672- const { configs, cliOverrides, verbose, dryRun, schemaOnly , unifiedCli } = options ;
671+ const { configs, cliOverrides, verbose, dryRun, schema , unifiedCli } = options ;
673672 const names = Object . keys ( configs ) ;
674673 const results : Array < { name : string ; result : GenerateResult } > = [ ] ;
675674 let hasError = false ;
676675
676+ const schemaEnabled = ! ! schema ?. enabled ;
677677 const targetInfos : RootRootReadmeTarget [ ] = [ ] ;
678- const useUnifiedCli = ! schemaOnly && ! ! unifiedCli && names . length > 1 ;
678+ const useUnifiedCli = ! schemaEnabled && ! ! unifiedCli && names . length > 1 ;
679679
680680 const cliTargets : MultiTargetCliTarget [ ] = [ ] ;
681681
@@ -693,8 +693,9 @@ export async function generateMulti(
693693 ...targetConfig ,
694694 verbose,
695695 dryRun,
696- schemaOnly,
697- schemaOnlyFilename : schemaOnly ? `${ name } .graphql` : undefined ,
696+ schema : schemaEnabled
697+ ? { ...schema , filename : schema ?. filename ?? `${ name } .graphql` }
698+ : targetConfig . schema ,
698699 } ,
699700 useUnifiedCli ? { skipCli : true , targetName : name } : { targetName : name } ,
700701 ) ;
0 commit comments