Skip to content

Commit c394518

Browse files
committed
feat: use inflekt@0.5.0 for shared name-matching and case helpers
- Bump inflekt to ^0.5.0 in graphql/query, graphql/codegen, graphile/graphile-settings - Import fuzzyFindByName directly from inflekt in field-selector.ts and select.ts - Delete local name-matching.ts (no longer needed) - Replace local lcFirst/ucFirst/toCamelCase/toPascalCase/toScreamingSnake in codegen/utils.ts with re-exports from inflekt (single source of truth)
1 parent 4c7e6c7 commit c394518

8 files changed

Lines changed: 2595 additions & 7523 deletions

File tree

graphile/graphile-settings/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"graphile-upload-plugin": "workspace:^",
5454
"graphile-utils": "5.0.0-rc.8",
5555
"graphql": "16.13.0",
56-
"inflekt": "^0.3.3",
56+
"inflekt": "^0.5.0",
5757
"lru-cache": "^11.2.7",
5858
"pg": "^8.20.0",
5959
"pg-query-context": "workspace:^",

graphql/codegen/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"gql-ast": "workspace:^",
6767
"graphile-schema": "workspace:^",
6868
"graphql": "16.13.0",
69-
"inflekt": "^0.3.3",
69+
"inflekt": "^0.5.0",
7070
"inquirerer": "^4.7.0",
7171
"jiti": "^2.6.1",
7272
"komoji": "^0.8.1",

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

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
/**
22
* Codegen utilities - naming conventions, type mapping, and helpers
33
*/
4-
import { pluralize } from 'inflekt';
4+
import {
5+
lcFirst,
6+
pluralize,
7+
toCamelCase,
8+
toPascalCase,
9+
toScreamingSnake,
10+
ucFirst,
11+
} from 'inflekt';
512

613
import type {
714
Field,
@@ -11,45 +18,8 @@ import type {
1118
} from '../../types/schema';
1219
import { scalarToFilterType, scalarToTsType } from './scalars';
1320

14-
// ============================================================================
15-
// String manipulation
16-
// NOTE: lcFirst, ucFirst already exist in inflekt; toCamelCase, toPascalCase,
17-
// toScreamingSnake are available in inflekt >=0.4.0. Once that version is
18-
// published these can be replaced with re-exports from inflekt.
19-
// ============================================================================
20-
21-
/** Lowercase first character */
22-
export function lcFirst(str: string): string {
23-
return str.charAt(0).toLowerCase() + str.slice(1);
24-
}
25-
26-
/** Uppercase first character */
27-
export function ucFirst(str: string): string {
28-
return str.charAt(0).toUpperCase() + str.slice(1);
29-
}
30-
31-
/** Convert to camelCase */
32-
export function toCamelCase(str: string): string {
33-
return str
34-
.replace(/[-_](.)/g, (_, char) => char.toUpperCase())
35-
.replace(/^(.)/, (_, char) => char.toLowerCase());
36-
}
37-
38-
/** Convert to PascalCase */
39-
export function toPascalCase(str: string): string {
40-
return str
41-
.replace(/[-_](.)/g, (_, char) => char.toUpperCase())
42-
.replace(/^(.)/, (_, char) => char.toUpperCase());
43-
}
44-
45-
/** Convert to SCREAMING_SNAKE_CASE */
46-
export function toScreamingSnake(str: string): string {
47-
return str
48-
.replace(/([A-Z])/g, '_$1')
49-
.replace(/[-\s]/g, '_')
50-
.toUpperCase()
51-
.replace(/^_/, '');
52-
}
21+
// Re-export string manipulation helpers from inflekt (single source of truth)
22+
export { lcFirst, toCamelCase, toPascalCase, toScreamingSnake, ucFirst };
5323

5424
// ============================================================================
5525
// Naming conventions for generated code

graphql/query/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"graphile-settings": "workspace:^",
3838
"graphql": "16.13.0",
3939
"inflection": "^3.0.0",
40-
"inflekt": "^0.3.3",
40+
"inflekt": "^0.5.0",
4141
"lru-cache": "^11.2.7",
4242
"postgraphile": "5.0.0-rc.10"
4343
},

graphql/query/src/generators/field-selector.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
FieldSelectionPreset,
1010
SimpleFieldSelection,
1111
} from '../types/selection';
12-
import { fuzzyFindByName } from './name-matching';
12+
import { fuzzyFindByName } from 'inflekt';
1313

1414
const relationalFieldSetCache = new WeakMap<Table, Set<string>>();
1515

@@ -294,9 +294,8 @@ function getRelatedTableScalarFields(
294294
return {};
295295
}
296296

297-
// Find the related table in allTables using shared fuzzy matching.
297+
// Find the related table in allTables using shared fuzzy matching from inflekt.
298298
// Handles PascalCase table names vs snake_case/camelCase/plural codec names.
299-
// TODO: replace with fuzzyFindByName from inflekt once 0.4.0 is published
300299
const relatedTable = fuzzyFindByName(
301300
allTables,
302301
referencedTableName,

graphql/query/src/generators/name-matching.ts

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

graphql/query/src/generators/select.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import type { QueryOptions } from '../types/query';
2525
import type { Table } from '../types/schema';
2626
import type { FieldSelection } from '../types/selection';
2727
import { convertToSelectionOptions, isRelationalField } from './field-selector';
28-
import { fuzzyFindByName } from './name-matching';
28+
import { fuzzyFindByName } from 'inflekt';
2929
import {
3030
normalizeInflectionValue,
3131
toCamelCasePlural,
@@ -788,9 +788,8 @@ function findRelatedTable(
788788
return null;
789789
}
790790

791-
// Find the related table using shared fuzzy matching.
791+
// Find the related table using shared fuzzy matching from inflekt.
792792
// Handles PascalCase table names vs snake_case/camelCase/plural codec names.
793-
// TODO: replace with fuzzyFindByName from inflekt once 0.4.0 is published
794793
return fuzzyFindByName(allTables, referencedTableName, (tbl) => tbl.name) ?? null;
795794
}
796795

0 commit comments

Comments
 (0)