@@ -21,6 +21,25 @@ export const splitCommas = (
2121 . filter ( Boolean ) ;
2222} ;
2323
24+ function normalizeListOption (
25+ input : unknown ,
26+ ) : string [ ] | undefined {
27+ if ( Array . isArray ( input ) ) {
28+ return input
29+ . flatMap ( ( item ) =>
30+ typeof item === 'string' ? ( splitCommas ( item ) ?? [ ] ) : [ String ( item ) ] ,
31+ )
32+ . map ( ( s ) => s . trim ( ) )
33+ . filter ( Boolean ) ;
34+ }
35+
36+ if ( typeof input === 'string' ) {
37+ return splitCommas ( input ) ;
38+ }
39+
40+ return undefined ;
41+ }
42+
2443export interface CodegenAnswers {
2544 endpoint ?: string ;
2645 schemaFile ?: string ;
@@ -188,6 +207,41 @@ export function buildDbConfig(
188207 return rest ;
189208}
190209
210+ /**
211+ * Normalizes top-level list-like CLI options to string arrays.
212+ * This keeps non-interactive paths equivalent to prompt sanitize behavior.
213+ */
214+ export function normalizeCodegenListOptions (
215+ options : Record < string , unknown > ,
216+ ) : Record < string , unknown > {
217+ return {
218+ ...options ,
219+ schemas : normalizeListOption ( options . schemas ) ,
220+ apiNames : normalizeListOption ( options . apiNames ) ,
221+ } ;
222+ }
223+
224+ /**
225+ * Returns true when source options are already available, so prompting can be skipped.
226+ */
227+ export function hasResolvedCodegenSource (
228+ options : Record < string , unknown > ,
229+ ) : boolean {
230+ const normalized = normalizeCodegenListOptions ( camelizeArgv ( options ) ) ;
231+ const db = normalized . db as Record < string , unknown > | undefined ;
232+ const dbSchemas = normalizeListOption ( db ?. schemas ) ;
233+ const dbApiNames = normalizeListOption ( db ?. apiNames ) ;
234+
235+ return Boolean (
236+ normalized . endpoint ||
237+ normalized . schemaFile ||
238+ ( normalized . schemas as string [ ] | undefined ) ?. length ||
239+ ( normalized . apiNames as string [ ] | undefined ) ?. length ||
240+ dbSchemas ?. length ||
241+ dbApiNames ?. length ,
242+ ) ;
243+ }
244+
191245export function seedArgvFromConfig (
192246 argv : Record < string , unknown > ,
193247 fileConfig : GraphQLSDKConfigTarget ,
@@ -203,6 +257,7 @@ export function buildGenerateOptions(
203257 fileConfig : GraphQLSDKConfigTarget = { } ,
204258) : GraphQLSDKConfigTarget {
205259 const camelized = camelizeArgv ( answers ) ;
206- const withDb = buildDbConfig ( camelized ) ;
260+ const normalized = normalizeCodegenListOptions ( camelized ) ;
261+ const withDb = buildDbConfig ( normalized ) ;
207262 return { ...fileConfig , ...withDb } as GraphQLSDKConfigTarget ;
208263}
0 commit comments