@constructive-io/graphql-codegen 4.15.3 → 4.15.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli/handler.js CHANGED
@@ -6,7 +6,13 @@ const generate_1 = require("../core/generate");
6
6
  const shared_1 = require("./shared");
7
7
  async function runCodegenHandler(argv, prompter) {
8
8
  const args = (0, shared_1.camelizeArgv)(argv);
9
- const schemaOnly = Boolean(args.schemaOnly);
9
+ const schemaConfig = args.schemaEnabled
10
+ ? {
11
+ enabled: true,
12
+ ...(args.schemaOutput ? { output: String(args.schemaOutput) } : {}),
13
+ ...(args.schemaFilename ? { filename: String(args.schemaFilename) } : {}),
14
+ }
15
+ : undefined;
10
16
  const hasSourceFlags = Boolean(args.endpoint || args.schemaFile || args.schemaDir || args.schemas || args.apiNames);
11
17
  const configPath = args.config ||
12
18
  (!hasSourceFlags ? (0, config_1.findConfigFile)() : undefined);
@@ -36,7 +42,7 @@ async function runCodegenHandler(argv, prompter) {
36
42
  const { results, hasError } = await (0, generate_1.generateMulti)({
37
43
  configs: selectedTargets,
38
44
  cliOverrides: cliOptions,
39
- schemaOnly,
45
+ schema: schemaConfig,
40
46
  });
41
47
  for (const { name, result } of results) {
42
48
  console.log(`\n[${name}]`);
@@ -59,7 +65,7 @@ async function runCodegenHandler(argv, prompter) {
59
65
  if (expanded) {
60
66
  const { results, hasError } = await (0, generate_1.generateMulti)({
61
67
  configs: expanded,
62
- schemaOnly,
68
+ schema: schemaConfig,
63
69
  });
64
70
  for (const { name, result } of results) {
65
71
  console.log(`\n[${name}]`);
@@ -69,6 +75,9 @@ async function runCodegenHandler(argv, prompter) {
69
75
  process.exit(1);
70
76
  return;
71
77
  }
72
- const result = await (0, generate_1.generate)({ ...options, schemaOnly });
78
+ const result = await (0, generate_1.generate)({
79
+ ...options,
80
+ ...(schemaConfig ? { schema: schemaConfig } : {}),
81
+ });
73
82
  (0, shared_1.printResult)(result);
74
83
  }
package/cli/index.js CHANGED
@@ -37,9 +37,11 @@ Generator Options:
37
37
  -v, --verbose Show detailed output
38
38
 
39
39
  Schema Export:
40
- --schema-only Export GraphQL SDL instead of running full codegen.
40
+ --schema-enabled Export GraphQL SDL instead of running full codegen.
41
41
  Works with any source (endpoint, file, database, PGPM).
42
42
  With multiple apiNames, writes one .graphql per API.
43
+ --schema-output <dir> Output directory for the exported schema file
44
+ --schema-filename <name> Filename for the exported schema (default: schema.graphql)
43
45
 
44
46
  -h, --help Show this help message
45
47
  --version Show version number
@@ -71,12 +73,14 @@ exports.options = {
71
73
  a: 'authorization',
72
74
  v: 'verbose',
73
75
  },
74
- boolean: ['schema-only'],
76
+ boolean: ['schema-enabled'],
75
77
  string: [
76
78
  'config',
77
79
  'endpoint',
78
80
  'schema-file',
79
81
  'schema-dir',
82
+ 'schema-output',
83
+ 'schema-filename',
80
84
  'output',
81
85
  'target',
82
86
  'authorization',
@@ -1,13 +1,10 @@
1
- import type { CliConfig, GraphQLSDKConfigTarget } from '../types/config';
1
+ import type { CliConfig, GraphQLSDKConfigTarget, SchemaConfig } from '../types/config';
2
2
  import type { CleanOperation, CleanTable, TypeRegistry } from '../types/schema';
3
3
  export interface GenerateOptions extends GraphQLSDKConfigTarget {
4
4
  authorization?: string;
5
5
  verbose?: boolean;
6
6
  dryRun?: boolean;
7
7
  skipCustomOperations?: boolean;
8
- schemaOnly?: boolean;
9
- schemaOnlyOutput?: string;
10
- schemaOnlyFilename?: string;
11
8
  }
12
9
  export interface GenerateResult {
13
10
  success: boolean;
@@ -47,7 +44,7 @@ export interface GenerateMultiOptions {
47
44
  cliOverrides?: Partial<GraphQLSDKConfigTarget>;
48
45
  verbose?: boolean;
49
46
  dryRun?: boolean;
50
- schemaOnly?: boolean;
47
+ schema?: SchemaConfig;
51
48
  unifiedCli?: CliConfig | boolean;
52
49
  }
53
50
  export interface GenerateMultiResult {
package/core/generate.js CHANGED
@@ -92,7 +92,8 @@ async function generate(options = {}, internalOptions) {
92
92
  // Auto-enable nodeHttpAdapter when CLI is enabled, unless explicitly set to false
93
93
  const useNodeHttpAdapter = options.nodeHttpAdapter === true ||
94
94
  (runCli && options.nodeHttpAdapter !== false);
95
- if (!options.schemaOnly && !runReactQuery && !runOrm && !runCli) {
95
+ const schemaEnabled = !!options.schema?.enabled;
96
+ if (!schemaEnabled && !runReactQuery && !runOrm && !runCli) {
96
97
  return {
97
98
  success: false,
98
99
  message: 'No generators enabled. Use reactQuery: true, orm: true, or cli: true in your config.',
@@ -119,7 +120,7 @@ async function generate(options = {}, internalOptions) {
119
120
  authorization: options.authorization || config.headers?.Authorization,
120
121
  headers: config.headers,
121
122
  });
122
- if (options.schemaOnly) {
123
+ if (schemaEnabled && !runReactQuery && !runOrm && !runCli) {
123
124
  try {
124
125
  console.log(`Fetching schema from ${source.describe()}...`);
125
126
  const { introspection } = await source.fetch();
@@ -132,9 +133,9 @@ async function generate(options = {}, internalOptions) {
132
133
  output: outputRoot,
133
134
  };
134
135
  }
135
- const outDir = node_path_1.default.resolve(options.schemaOnlyOutput || outputRoot || '.');
136
+ const outDir = node_path_1.default.resolve(options.schema?.output || outputRoot || '.');
136
137
  await fs.promises.mkdir(outDir, { recursive: true });
137
- const filename = options.schemaOnlyFilename || 'schema.graphql';
138
+ const filename = options.schema?.filename || 'schema.graphql';
138
139
  const filePath = node_path_1.default.join(outDir, filename);
139
140
  await fs.promises.writeFile(filePath, sdl, 'utf-8');
140
141
  return {
@@ -539,12 +540,13 @@ function applySharedPgpmDb(config, sharedSources) {
539
540
  };
540
541
  }
541
542
  async function generateMulti(options) {
542
- const { configs, cliOverrides, verbose, dryRun, schemaOnly, unifiedCli } = options;
543
+ const { configs, cliOverrides, verbose, dryRun, schema, unifiedCli } = options;
543
544
  const names = Object.keys(configs);
544
545
  const results = [];
545
546
  let hasError = false;
547
+ const schemaEnabled = !!schema?.enabled;
546
548
  const targetInfos = [];
547
- const useUnifiedCli = !schemaOnly && !!unifiedCli && names.length > 1;
549
+ const useUnifiedCli = !schemaEnabled && !!unifiedCli && names.length > 1;
548
550
  const cliTargets = [];
549
551
  const sharedSources = await prepareSharedPgpmSources(configs, cliOverrides);
550
552
  try {
@@ -558,8 +560,9 @@ async function generateMulti(options) {
558
560
  ...targetConfig,
559
561
  verbose,
560
562
  dryRun,
561
- schemaOnly,
562
- schemaOnlyFilename: schemaOnly ? `${name}.graphql` : undefined,
563
+ schema: schemaEnabled
564
+ ? { ...schema, filename: schema?.filename ?? `${name}.graphql` }
565
+ : targetConfig.schema,
563
566
  }, useUnifiedCli ? { skipCli: true, targetName: name } : { targetName: name });
564
567
  results.push({ name, result });
565
568
  if (!result.success) {
@@ -3,7 +3,13 @@ import { expandApiNamesToMultiTarget, expandSchemaDirToMultiTarget, generate, ge
3
3
  import { buildDbConfig, buildGenerateOptions, camelizeArgv, codegenQuestions, hasResolvedCodegenSource, normalizeCodegenListOptions, printResult, seedArgvFromConfig, } from './shared';
4
4
  export async function runCodegenHandler(argv, prompter) {
5
5
  const args = camelizeArgv(argv);
6
- const schemaOnly = Boolean(args.schemaOnly);
6
+ const schemaConfig = args.schemaEnabled
7
+ ? {
8
+ enabled: true,
9
+ ...(args.schemaOutput ? { output: String(args.schemaOutput) } : {}),
10
+ ...(args.schemaFilename ? { filename: String(args.schemaFilename) } : {}),
11
+ }
12
+ : undefined;
7
13
  const hasSourceFlags = Boolean(args.endpoint || args.schemaFile || args.schemaDir || args.schemas || args.apiNames);
8
14
  const configPath = args.config ||
9
15
  (!hasSourceFlags ? findConfigFile() : undefined);
@@ -33,7 +39,7 @@ export async function runCodegenHandler(argv, prompter) {
33
39
  const { results, hasError } = await generateMulti({
34
40
  configs: selectedTargets,
35
41
  cliOverrides: cliOptions,
36
- schemaOnly,
42
+ schema: schemaConfig,
37
43
  });
38
44
  for (const { name, result } of results) {
39
45
  console.log(`\n[${name}]`);
@@ -56,7 +62,7 @@ export async function runCodegenHandler(argv, prompter) {
56
62
  if (expanded) {
57
63
  const { results, hasError } = await generateMulti({
58
64
  configs: expanded,
59
- schemaOnly,
65
+ schema: schemaConfig,
60
66
  });
61
67
  for (const { name, result } of results) {
62
68
  console.log(`\n[${name}]`);
@@ -66,6 +72,9 @@ export async function runCodegenHandler(argv, prompter) {
66
72
  process.exit(1);
67
73
  return;
68
74
  }
69
- const result = await generate({ ...options, schemaOnly });
75
+ const result = await generate({
76
+ ...options,
77
+ ...(schemaConfig ? { schema: schemaConfig } : {}),
78
+ });
70
79
  printResult(result);
71
80
  }
package/esm/cli/index.js CHANGED
@@ -34,9 +34,11 @@ Generator Options:
34
34
  -v, --verbose Show detailed output
35
35
 
36
36
  Schema Export:
37
- --schema-only Export GraphQL SDL instead of running full codegen.
37
+ --schema-enabled Export GraphQL SDL instead of running full codegen.
38
38
  Works with any source (endpoint, file, database, PGPM).
39
39
  With multiple apiNames, writes one .graphql per API.
40
+ --schema-output <dir> Output directory for the exported schema file
41
+ --schema-filename <name> Filename for the exported schema (default: schema.graphql)
40
42
 
41
43
  -h, --help Show this help message
42
44
  --version Show version number
@@ -67,12 +69,14 @@ export const options = {
67
69
  a: 'authorization',
68
70
  v: 'verbose',
69
71
  },
70
- boolean: ['schema-only'],
72
+ boolean: ['schema-enabled'],
71
73
  string: [
72
74
  'config',
73
75
  'endpoint',
74
76
  'schema-file',
75
77
  'schema-dir',
78
+ 'schema-output',
79
+ 'schema-filename',
76
80
  'output',
77
81
  'target',
78
82
  'authorization',
@@ -1,13 +1,10 @@
1
- import type { CliConfig, GraphQLSDKConfigTarget } from '../types/config';
1
+ import type { CliConfig, GraphQLSDKConfigTarget, SchemaConfig } from '../types/config';
2
2
  import type { CleanOperation, CleanTable, TypeRegistry } from '../types/schema';
3
3
  export interface GenerateOptions extends GraphQLSDKConfigTarget {
4
4
  authorization?: string;
5
5
  verbose?: boolean;
6
6
  dryRun?: boolean;
7
7
  skipCustomOperations?: boolean;
8
- schemaOnly?: boolean;
9
- schemaOnlyOutput?: string;
10
- schemaOnlyFilename?: string;
11
8
  }
12
9
  export interface GenerateResult {
13
10
  success: boolean;
@@ -47,7 +44,7 @@ export interface GenerateMultiOptions {
47
44
  cliOverrides?: Partial<GraphQLSDKConfigTarget>;
48
45
  verbose?: boolean;
49
46
  dryRun?: boolean;
50
- schemaOnly?: boolean;
47
+ schema?: SchemaConfig;
51
48
  unifiedCli?: CliConfig | boolean;
52
49
  }
53
50
  export interface GenerateMultiResult {
@@ -50,7 +50,8 @@ export async function generate(options = {}, internalOptions) {
50
50
  // Auto-enable nodeHttpAdapter when CLI is enabled, unless explicitly set to false
51
51
  const useNodeHttpAdapter = options.nodeHttpAdapter === true ||
52
52
  (runCli && options.nodeHttpAdapter !== false);
53
- if (!options.schemaOnly && !runReactQuery && !runOrm && !runCli) {
53
+ const schemaEnabled = !!options.schema?.enabled;
54
+ if (!schemaEnabled && !runReactQuery && !runOrm && !runCli) {
54
55
  return {
55
56
  success: false,
56
57
  message: 'No generators enabled. Use reactQuery: true, orm: true, or cli: true in your config.',
@@ -77,7 +78,7 @@ export async function generate(options = {}, internalOptions) {
77
78
  authorization: options.authorization || config.headers?.Authorization,
78
79
  headers: config.headers,
79
80
  });
80
- if (options.schemaOnly) {
81
+ if (schemaEnabled && !runReactQuery && !runOrm && !runCli) {
81
82
  try {
82
83
  console.log(`Fetching schema from ${source.describe()}...`);
83
84
  const { introspection } = await source.fetch();
@@ -90,9 +91,9 @@ export async function generate(options = {}, internalOptions) {
90
91
  output: outputRoot,
91
92
  };
92
93
  }
93
- const outDir = path.resolve(options.schemaOnlyOutput || outputRoot || '.');
94
+ const outDir = path.resolve(options.schema?.output || outputRoot || '.');
94
95
  await fs.promises.mkdir(outDir, { recursive: true });
95
- const filename = options.schemaOnlyFilename || 'schema.graphql';
96
+ const filename = options.schema?.filename || 'schema.graphql';
96
97
  const filePath = path.join(outDir, filename);
97
98
  await fs.promises.writeFile(filePath, sdl, 'utf-8');
98
99
  return {
@@ -497,12 +498,13 @@ function applySharedPgpmDb(config, sharedSources) {
497
498
  };
498
499
  }
499
500
  export async function generateMulti(options) {
500
- const { configs, cliOverrides, verbose, dryRun, schemaOnly, unifiedCli } = options;
501
+ const { configs, cliOverrides, verbose, dryRun, schema, unifiedCli } = options;
501
502
  const names = Object.keys(configs);
502
503
  const results = [];
503
504
  let hasError = false;
505
+ const schemaEnabled = !!schema?.enabled;
504
506
  const targetInfos = [];
505
- const useUnifiedCli = !schemaOnly && !!unifiedCli && names.length > 1;
507
+ const useUnifiedCli = !schemaEnabled && !!unifiedCli && names.length > 1;
506
508
  const cliTargets = [];
507
509
  const sharedSources = await prepareSharedPgpmSources(configs, cliOverrides);
508
510
  try {
@@ -516,8 +518,9 @@ export async function generateMulti(options) {
516
518
  ...targetConfig,
517
519
  verbose,
518
520
  dryRun,
519
- schemaOnly,
520
- schemaOnlyFilename: schemaOnly ? `${name}.graphql` : undefined,
521
+ schema: schemaEnabled
522
+ ? { ...schema, filename: schema?.filename ?? `${name}.graphql` }
523
+ : targetConfig.schema,
521
524
  }, useUnifiedCli ? { skipCli: true, targetName: name } : { targetName: name });
522
525
  results.push({ name, result });
523
526
  if (!result.success) {
@@ -145,6 +145,29 @@ export interface DocsConfig {
145
145
  */
146
146
  skills?: boolean;
147
147
  }
148
+ /**
149
+ * Schema export configuration
150
+ * Controls SDL schema export behavior.
151
+ */
152
+ export interface SchemaConfig {
153
+ /**
154
+ * Enable schema SDL export
155
+ * When true, fetches the schema and writes it as a .graphql SDL file.
156
+ * If no generators are enabled (orm, reactQuery, cli), only the schema is exported.
157
+ * @default false
158
+ */
159
+ enabled?: boolean;
160
+ /**
161
+ * Output directory for the exported schema file
162
+ * @default same as the target's output directory
163
+ */
164
+ output?: string;
165
+ /**
166
+ * Filename for the exported schema file
167
+ * @default 'schema.graphql'
168
+ */
169
+ filename?: string;
170
+ }
148
171
  /**
149
172
  * Infrastructure command name overrides for collision handling.
150
173
  * When a target name collides with a default infra command name,
@@ -340,6 +363,12 @@ export interface GraphQLSDKConfigTarget {
340
363
  * @default { readme: true, agents: true, mcp: false }
341
364
  */
342
365
  docs?: DocsConfig | boolean;
366
+ /**
367
+ * Schema export configuration
368
+ * When enabled, exports the GraphQL SDL to a file.
369
+ * If no generators are also enabled, this acts as a schema-only export.
370
+ */
371
+ schema?: SchemaConfig;
343
372
  /**
344
373
  * Custom path for generated skill files.
345
374
  * When set, skills are written to this directory.
@@ -5,5 +5,5 @@ export type { CleanBelongsToRelation, CleanField, CleanFieldType, CleanHasManyRe
5
5
  export type { ConnectionResult, FieldFilter, Filter, FilterOperator, OrderByItem, PageInfo, QueryOptions, RelationalFilter, } from './query';
6
6
  export type { CreateInput, DeleteInput, MutationOptions, MutationResult, UpdateInput, } from './mutation';
7
7
  export type { FieldSelection, FieldSelectionPreset, SelectionOptions, SimpleFieldSelection, } from './selection';
8
- export type { GraphQLSDKConfig, GraphQLSDKConfigTarget } from './config';
8
+ export type { GraphQLSDKConfig, GraphQLSDKConfigTarget, SchemaConfig } from './config';
9
9
  export { DEFAULT_CONFIG, defineConfig, getConfigOptions, mergeConfig, } from './config';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructive-io/graphql-codegen",
3
- "version": "4.15.3",
3
+ "version": "4.15.4",
4
4
  "description": "GraphQL SDK generator for Constructive databases with React Query hooks",
5
5
  "keywords": [
6
6
  "graphql",
@@ -101,5 +101,5 @@
101
101
  "tsx": "^4.21.0",
102
102
  "typescript": "^5.9.3"
103
103
  },
104
- "gitHead": "c18ef8e002d958001fe69fff3758d1f89613eb2b"
104
+ "gitHead": "8edfd4913d37603659afa968489dc84d6bab769d"
105
105
  }
package/types/config.d.ts CHANGED
@@ -145,6 +145,29 @@ export interface DocsConfig {
145
145
  */
146
146
  skills?: boolean;
147
147
  }
148
+ /**
149
+ * Schema export configuration
150
+ * Controls SDL schema export behavior.
151
+ */
152
+ export interface SchemaConfig {
153
+ /**
154
+ * Enable schema SDL export
155
+ * When true, fetches the schema and writes it as a .graphql SDL file.
156
+ * If no generators are enabled (orm, reactQuery, cli), only the schema is exported.
157
+ * @default false
158
+ */
159
+ enabled?: boolean;
160
+ /**
161
+ * Output directory for the exported schema file
162
+ * @default same as the target's output directory
163
+ */
164
+ output?: string;
165
+ /**
166
+ * Filename for the exported schema file
167
+ * @default 'schema.graphql'
168
+ */
169
+ filename?: string;
170
+ }
148
171
  /**
149
172
  * Infrastructure command name overrides for collision handling.
150
173
  * When a target name collides with a default infra command name,
@@ -340,6 +363,12 @@ export interface GraphQLSDKConfigTarget {
340
363
  * @default { readme: true, agents: true, mcp: false }
341
364
  */
342
365
  docs?: DocsConfig | boolean;
366
+ /**
367
+ * Schema export configuration
368
+ * When enabled, exports the GraphQL SDL to a file.
369
+ * If no generators are also enabled, this acts as a schema-only export.
370
+ */
371
+ schema?: SchemaConfig;
343
372
  /**
344
373
  * Custom path for generated skill files.
345
374
  * When set, skills are written to this directory.
package/types/index.d.ts CHANGED
@@ -5,5 +5,5 @@ export type { CleanBelongsToRelation, CleanField, CleanFieldType, CleanHasManyRe
5
5
  export type { ConnectionResult, FieldFilter, Filter, FilterOperator, OrderByItem, PageInfo, QueryOptions, RelationalFilter, } from './query';
6
6
  export type { CreateInput, DeleteInput, MutationOptions, MutationResult, UpdateInput, } from './mutation';
7
7
  export type { FieldSelection, FieldSelectionPreset, SelectionOptions, SimpleFieldSelection, } from './selection';
8
- export type { GraphQLSDKConfig, GraphQLSDKConfigTarget } from './config';
8
+ export type { GraphQLSDKConfig, GraphQLSDKConfigTarget, SchemaConfig } from './config';
9
9
  export { DEFAULT_CONFIG, defineConfig, getConfigOptions, mergeConfig, } from './config';