Skip to content

Commit ddcc81d

Browse files
committed
refactor(codegen): remove deprecations, unify camelizeArgv, clean up redundant wrappers
- Undeprecate generators/index.ts (active v5 code, not legacy v4) - Undeprecate MetaObject/QueryBuilder exports in core/index.ts - Remove deprecated formatOutput() and its test (replaced by writeGeneratedFiles) - Remove buildSchemaSDLFromDatabase() wrapper, callers use buildSchemaSDL directly - Unify camelizeArgv: camelize once at top of each CLI handler, remove dual manual-kebab + later-camelize pattern
1 parent 5a14718 commit ddcc81d

11 files changed

Lines changed: 24 additions & 141 deletions

File tree

graphql/codegen/src/__tests__/codegen/format-output.test.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

graphql/codegen/src/cli/index.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,17 @@ export const commands = async (
7171
process.exit(0);
7272
}
7373

74-
const schemaOnly = Boolean(argv['schema-only']);
74+
const args = camelizeArgv(argv as Record<string, any>);
75+
76+
const schemaOnly = Boolean(args.schemaOnly);
7577

7678
const hasSourceFlags = Boolean(
77-
argv.endpoint ||
78-
argv.e ||
79-
argv['schema-file'] ||
80-
argv.s ||
81-
argv.schemas ||
82-
argv['api-names'],
79+
args.endpoint || args.schemaFile || args.schemas || args.apiNames
8380
);
84-
const explicitConfigPath = (argv.config || argv.c) as string | undefined;
8581
const configPath =
86-
explicitConfigPath || (!hasSourceFlags ? findConfigFile() : undefined);
87-
const targetName = (argv.target || argv.t) as string | undefined;
82+
(args.config as string | undefined) ||
83+
(!hasSourceFlags ? findConfigFile() : undefined);
84+
const targetName = args.target as string | undefined;
8885

8986
let fileConfig: GraphQLSDKConfigTarget = {};
9087

@@ -114,9 +111,7 @@ export const commands = async (
114111
}
115112

116113
const cliOptions = buildDbConfig(
117-
normalizeCodegenListOptions(
118-
camelizeArgv(argv as Record<string, any>),
119-
),
114+
normalizeCodegenListOptions(args),
120115
);
121116

122117
const selectedTargets = targetName
@@ -142,7 +137,7 @@ export const commands = async (
142137
fileConfig = config as GraphQLSDKConfigTarget;
143138
}
144139

145-
const seeded = seedArgvFromConfig(argv, fileConfig);
140+
const seeded = seedArgvFromConfig(args, fileConfig);
146141
const answers = hasResolvedCodegenSource(seeded)
147142
? seeded
148143
: await prompter.prompt(seeded, codegenQuestions);

graphql/codegen/src/core/database/index.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,3 @@ export async function buildSchemaFromDatabase(
5656

5757
return { schemaPath, sdl };
5858
}
59-
60-
/**
61-
* Build a GraphQL schema SDL string from a PostgreSQL database without writing to file.
62-
*
63-
* This is a convenience wrapper around buildSchemaSDL from graphql-server.
64-
*
65-
* @param options - Configuration options
66-
* @returns The SDL content as a string
67-
*/
68-
export async function buildSchemaSDLFromDatabase(options: {
69-
database: string;
70-
schemas: string[];
71-
}): Promise<string> {
72-
const { database, schemas } = options;
73-
74-
// PostGraphile v5 resolves role/settings via preset configuration.
75-
return buildSchemaSDL({
76-
database,
77-
schemas,
78-
});
79-
}

graphql/codegen/src/core/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ export * from './ast';
1717
export * from './custom-ast';
1818

1919
// Query builder
20-
/** @deprecated Legacy v4 query builder — use v5 ORM codegen instead */
2120
export { MetaObject, QueryBuilder } from './query-builder';
2221

2322
// Meta object utilities
24-
/** @deprecated Legacy v4 meta-object utilities — v5 uses standard introspection */
2523
export { convertFromMetaSchema, validateMetaObject } from './meta-object';
2624

2725
// Configuration loading and resolution

graphql/codegen/src/core/introspect/source/database.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
*/
77
import { buildSchema, introspectionFromSchema } from 'graphql';
88

9+
import { buildSchemaSDL } from '@constructive-io/graphql-server';
10+
911
import type { IntrospectionQueryResponse } from '../../../types/introspection';
10-
import { buildSchemaSDLFromDatabase } from '../../database';
1112
import {
1213
createDatabasePool,
1314
resolveApiSchemas,
@@ -80,7 +81,7 @@ export class DatabaseSchemaSource implements SchemaSource {
8081
// Build SDL from database
8182
let sdl: string;
8283
try {
83-
sdl = await buildSchemaSDLFromDatabase({
84+
sdl = await buildSchemaSDL({
8485
database,
8586
schemas,
8687
});

graphql/codegen/src/core/introspect/source/pgpm-module.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import { getPgPool } from 'pg-cache';
1313
import { createEphemeralDb, type EphemeralDbResult } from 'pgsql-client';
1414
import { deployPgpm } from 'pgsql-seed';
1515

16+
import { buildSchemaSDL } from '@constructive-io/graphql-server';
17+
1618
import type { IntrospectionQueryResponse } from '../../../types/introspection';
17-
import { buildSchemaSDLFromDatabase } from '../../database';
1819
import { resolveApiSchemas, validateServicesSchemas } from './api-schemas';
1920
import type { SchemaSource, SchemaSourceResult } from './types';
2021
import { SchemaSourceError } from './types';
@@ -199,7 +200,7 @@ export class PgpmModuleSchemaSource implements SchemaSource {
199200
// Build SDL from the deployed database
200201
let sdl: string;
201202
try {
202-
sdl = await buildSchemaSDLFromDatabase({
203+
sdl = await buildSchemaSDL({
203204
database: dbConfig.database,
204205
schemas,
205206
});

graphql/codegen/src/core/output/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
export {
6-
formatOutput,
76
type GeneratedFile,
87
writeGeneratedFiles,
98
type WriteOptions,

graphql/codegen/src/core/output/writer.ts

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -225,43 +225,3 @@ function findTsFiles(dir: string): string[] {
225225

226226
return files;
227227
}
228-
229-
/**
230-
* Format generated files using oxfmt programmatically
231-
*
232-
* @deprecated Use writeGeneratedFiles with formatFiles option instead.
233-
* This function is kept for backwards compatibility.
234-
*/
235-
export async function formatOutput(
236-
outputDir: string,
237-
): Promise<{ success: boolean; error?: string }> {
238-
const formatFn = await getOxfmtFormat();
239-
if (!formatFn) {
240-
return {
241-
success: false,
242-
error: 'oxfmt not available. Install it with: npm install oxfmt',
243-
};
244-
}
245-
246-
const absoluteOutputDir = path.resolve(outputDir);
247-
248-
try {
249-
// Find all .ts files in the output directory
250-
const tsFiles = findTsFiles(absoluteOutputDir);
251-
252-
for (const filePath of tsFiles) {
253-
const content = fs.readFileSync(filePath, 'utf-8');
254-
const formatted = await formatFileContent(
255-
path.basename(filePath),
256-
content,
257-
formatFn,
258-
);
259-
fs.writeFileSync(filePath, formatted, 'utf-8');
260-
}
261-
262-
return { success: true };
263-
} catch (err) {
264-
const message = err instanceof Error ? err.message : String(err);
265-
return { success: false, error: message };
266-
}
267-
}

graphql/codegen/src/generators/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
/**
22
* Query and mutation generator exports
3-
*
4-
* @deprecated Legacy v4 generators — use v5 ORM codegen pipeline instead.
5-
* These are retained for backward compatibility with existing v4 consumers.
63
*/
74

85
// Field selector utilities

graphql/codegen/src/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,4 @@ export type {
5050
BuildSchemaFromDatabaseOptions,
5151
BuildSchemaFromDatabaseResult,
5252
} from './core/database';
53-
export {
54-
buildSchemaFromDatabase,
55-
buildSchemaSDLFromDatabase,
56-
} from './core/database';
53+
export { buildSchemaFromDatabase } from './core/database';

0 commit comments

Comments
 (0)