Skip to content

Commit 85c25d7

Browse files
committed
refactor: unify casing — use toConstantCase (komoji) instead of toScreamingSnake, toSnakeCase instead of underscore
- Replace all toScreamingSnake imports/usage with toConstantCase from komoji - Replace all underscore imports/usage with toSnakeCase from komoji - Add komoji dependency to graphql/query - Update tests to use toConstantCase - All 312 codegen tests pass, full monorepo build succeeds
1 parent cb1a959 commit 85c25d7

7 files changed

Lines changed: 2799 additions & 7440 deletions

File tree

graphql/codegen/src/__tests__/codegen/utils.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
lcFirst,
1212
toCamelCase,
1313
toPascalCase,
14-
toScreamingSnake,
14+
toConstantCase,
1515
ucFirst,
1616
} from '../../core/codegen/utils';
1717
import type { Relations, Table } from '../../types/schema';
@@ -62,10 +62,10 @@ describe('utils', () => {
6262
expect(toPascalCase('helloWorld')).toBe('HelloWorld');
6363
});
6464

65-
it('toScreamingSnake converts to SCREAMING_SNAKE_CASE', () => {
66-
expect(toScreamingSnake('helloWorld')).toBe('HELLO_WORLD');
67-
expect(toScreamingSnake('HelloWorld')).toBe('HELLO_WORLD');
68-
expect(toScreamingSnake('hello')).toBe('HELLO');
65+
it('toConstantCase converts to CONSTANT_CASE', () => {
66+
expect(toConstantCase('helloWorld')).toBe('HELLO_WORLD');
67+
expect(toConstantCase('HelloWorld')).toBe('HELLO_WORLD');
68+
expect(toConstantCase('hello')).toBe('HELLO');
6969
});
7070
});
7171

graphql/codegen/src/core/codegen/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {
66
pluralize,
77
toCamelCase,
88
toPascalCase,
9-
toScreamingSnake,
109
ucFirst,
1110
} from 'inflekt';
11+
import { toConstantCase } from 'komoji';
1212

1313
import type {
1414
Field,
@@ -19,7 +19,7 @@ import type {
1919
import { scalarToFilterType, scalarToTsType } from './scalars';
2020

2121
// Re-export string manipulation helpers from inflekt (single source of truth)
22-
export { lcFirst, toCamelCase, toPascalCase, toScreamingSnake, ucFirst };
22+
export { lcFirst, toCamelCase, toPascalCase, toConstantCase, ucFirst };
2323

2424
// ============================================================================
2525
// Naming conventions for generated code

graphql/query/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"graphql": "16.13.0",
3939
"inflection": "^3.0.0",
4040
"inflekt": "^0.5.1",
41+
"komoji": "^0.8.1",
4142
"lru-cache": "^11.2.7",
4243
"postgraphile": "5.0.0-rc.10"
4344
},

graphql/query/src/generators/naming-helpers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
*
88
* Back-ported from Dashboard's `packages/data/src/query-generator.ts`.
99
*/
10-
import { toCamelCase, toScreamingSnake, pluralize } from 'inflekt';
10+
import { toCamelCase, pluralize } from 'inflekt';
11+
import { toConstantCase } from 'komoji';
1112

1213
import type { Table } from '../types/schema';
1314

@@ -206,7 +207,7 @@ export function toOrderByEnumValue(
206207
fieldName: string,
207208
direction: 'asc' | 'desc',
208209
): string {
209-
const screaming = toScreamingSnake(fieldName);
210+
const screaming = toConstantCase(fieldName);
210211
return `${screaming}_${direction.toUpperCase()}`;
211212
}
212213

graphql/query/src/query-builder.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { DocumentNode, print as gqlPrint } from 'graphql';
2-
import { toCamelCase, toPascalCase, pluralize, underscore } from 'inflekt';
2+
import { toCamelCase, toPascalCase, pluralize } from 'inflekt';
3+
import { toSnakeCase } from 'komoji';
34

45
import {
56
createOne,
@@ -194,7 +195,7 @@ export class QueryBuilder {
194195
this._key = this._findQuery();
195196

196197
this.queryName(
197-
toCamelCase(['get', underscore(this._key), 'query'].join('_')),
198+
toCamelCase(['get', toSnakeCase(this._key), 'query'].join('_')),
198199
);
199200

200201
const defn = this._introspection[this._key];
@@ -216,7 +217,7 @@ export class QueryBuilder {
216217
this._key = this._findQuery();
217218

218219
this.queryName(
219-
toCamelCase(['get', underscore(this._key), 'query', 'all'].join('_')),
220+
toCamelCase(['get', toSnakeCase(this._key), 'query', 'all'].join('_')),
220221
);
221222

222223
const defn = this._introspection[this._key];
@@ -238,7 +239,7 @@ export class QueryBuilder {
238239

239240
this.queryName(
240241
toCamelCase(
241-
['get', underscore(this._key), 'count', 'query'].join('_'),
242+
['get', toSnakeCase(this._key), 'count', 'query'].join('_'),
242243
),
243244
);
244245

@@ -258,7 +259,7 @@ export class QueryBuilder {
258259
this._key = this._findQuery();
259260

260261
this.queryName(
261-
toCamelCase(['get', underscore(this._key), 'query'].join('_')),
262+
toCamelCase(['get', toSnakeCase(this._key), 'query'].join('_')),
262263
);
263264

264265
const defn = this._introspection[this._key];
@@ -280,7 +281,7 @@ export class QueryBuilder {
280281
this._key = this._findMutation();
281282

282283
this.queryName(
283-
toCamelCase([underscore(this._key), 'mutation'].join('_')),
284+
toCamelCase([toSnakeCase(this._key), 'mutation'].join('_')),
284285
);
285286

286287
const defn = this._introspection[this._key] as MutationDefinition;
@@ -301,7 +302,7 @@ export class QueryBuilder {
301302
this._key = this._findMutation();
302303

303304
this.queryName(
304-
toCamelCase([underscore(this._key), 'mutation'].join('_')),
305+
toCamelCase([toSnakeCase(this._key), 'mutation'].join('_')),
305306
);
306307

307308
const defn = this._introspection[this._key] as MutationDefinition;
@@ -322,7 +323,7 @@ export class QueryBuilder {
322323
this._key = this._findMutation();
323324

324325
this.queryName(
325-
toCamelCase([underscore(this._key), 'mutation'].join('_')),
326+
toCamelCase([toSnakeCase(this._key), 'mutation'].join('_')),
326327
);
327328

328329
const defn = this._introspection[this._key] as MutationDefinition;
@@ -559,5 +560,5 @@ function isRelationalField(fieldName: string, modelMeta: MetaTable): boolean {
559560
// Get getMany op name from model
560561
// ie. UserSetting => userSettings
561562
function modelNameToGetMany(model: string): string {
562-
return toCamelCase(pluralize(underscore(model)));
563+
return toCamelCase(pluralize(toSnakeCase(model)));
563564
}

pgpm/export/src/graphql-naming.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
* db_migrate.sql_actions -> sqlActions
1414
* column database_id -> databaseId
1515
*/
16-
import { toCamelCase, toPascalCase, distinctPluralize, singularizeLast, underscore } from 'inflekt';
16+
import { toCamelCase, toPascalCase, distinctPluralize, singularizeLast } from 'inflekt';
17+
import { toSnakeCase } from 'komoji';
1718

1819
/**
1920
* Get the GraphQL query field name for a given Postgres table name.
@@ -36,7 +37,7 @@ export const graphqlRowToPostgresRow = (
3637
): Record<string, unknown> => {
3738
const result: Record<string, unknown> = {};
3839
for (const [key, value] of Object.entries(row)) {
39-
result[underscore(key)] = value;
40+
result[toSnakeCase(key)] = value;
4041
}
4142
return result;
4243
};

0 commit comments

Comments
 (0)