Skip to content

Conversation

@theothersideofgod
Copy link
Contributor

@theothersideofgod theothersideofgod commented Jan 6, 2026

Summary

Fixes incorrect pluralization of 'regimen' that caused naming conflicts in GraphQL schema generation when both 'regimen' and 'regimens' tables existed.

Problem:

  • The underlying 'pluralize' npm package incorrectly handles 'regimen'
  • singularize('regimen') returned 'regiman' instead of 'regimen'
  • pluralize('regimen') returned 'regimen' (no change)
  • PostGraphile generated conflicting type names (RegimenOrderBy vs RegimensOrderBy)

Solution:

  • Replaced the default pluralize library with the new inflekt@0.1.0 package for pluralize/singularize operations
  • The inflekt library correctly handles 'regimen' → 'regimens' and other edge cases including Latin suffix overrides (schemata → schema, criteria → criterion, etc.)
  • Updated both graphile-simple-inflector and graphql-codegen packages to use inflekt

Changes:

  • Added inflekt package as a dependency to graphile-simple-inflector and graphql-codegen
  • Removed inflection package dependency from both packages
  • Deleted pluralize.ts wrapper file in codegen - all files now import directly from inflekt
  • Updated all inflection function calls across codegen files (ast.ts, query-builder.ts, mutations.ts, select.ts, infer-tables.ts, utils.ts, input-types-generator.ts) to use direct imports from inflekt
  • Added comprehensive test suite with SQL fixtures for various table naming patterns
  • Added snapshot tests for GraphQL schema generation

Updates since last revision

  • Rebased onto latest main branch to resolve conflicts
  • Replaced inflection package with newly published inflekt@0.1.0 in both graphile-simple-inflector and graphql-codegen
  • Deleted codegen's pluralize.ts wrapper file entirely - all imports now come directly from inflekt
  • Updated index.ts to re-export singularize/pluralize from inflekt for module API compatibility

Review & Testing Checklist for Human

  • Verify inflekt@0.1.0 exports all required functions (camelize, singularize, pluralize, underscore, lcFirst, ucFirst, toFieldName, toQueryName) - this is a newly published package
  • Test with existing production schemas to ensure no breaking changes to GraphQL type names
  • Verify the inflekt library handles edge cases correctly (e.g., 'child'/'children', 'man'/'men', 'regimen'/'regimens', 'schemata'/'schema')
  • Review snapshot file changes to confirm generated type names are correct (e.g., UserRegimensOrderBy, RegimenCondition)
  • Run the test suite locally: cd graphile/graphile-simple-inflector && pnpm test

Recommended test plan: Create test tables with singular and plural names (regimen, regimens, user_regimen) and verify PostGraphile generates non-conflicting, correctly-named GraphQL types. Also test codegen output to ensure generated TypeScript uses correct pluralization.

Notes

This PR uses the newly published inflekt@0.1.0 package which wraps the inflection npm package with PostGraphile-compatible Latin suffix overrides. Since inflekt is a new package (v0.1.0), extra verification is recommended.

Link to Devin run: https://app.devin.ai/sessions/0a2a8e7889894852863ad967c5e79636
Requested by: Dan Lynch (@pyramation)

Problem:
- The 'regimen' word was incorrectly pluralized by the pluralize library
- This caused naming conflicts in GraphQL schema generation when both
  'regimen' and 'regimens' tables existed
- PostGraphile generated conflicting type names (RegimenOrderBy vs RegimensOrderBy)

Root Cause:
- The underlying 'pluralize' npm package incorrectly handles 'regimen'
- singularize('regimen') returned 'regiman' instead of 'regimen'
- pluralize('regimen') returned 'regimen' (no change)
- isPlural('regimen') returned true

Solution:
- Added special rules in pluralize() and singularize() methods to handle
  'regimen' and 'regimens' correctly
- These rules check for exact matches (case-insensitive) before falling
  back to the default pluralize library behavior
- This ensures backward compatibility for all other words

Changes:
- Added special cases for 'regimen' -> 'regimens' in pluralize()
- Added special cases for 'regimens' -> 'regimen' in singularize()
- Updated distinctPluralize() to handle 'regimen' correctly
- Added comprehensive test suite for singular, plural, and compound table names
- Removed all debug console.log statements

Testing:
- Added inflection-special-cases.test.ts with test cases for:
  - Singular tables: regimen, child, man, user_login
  - Plural tables: regimens, children, men, user_logins
  - Compound tables: user_regimen, user_regimens
- All tests pass and snapshots are correct
…handling

- Add inflection library as dependency
- Replace oldInflection.pluralize/singularize with inflection library
- Remove hardcoded regimen special cases
- All tests passing
@devin-ai-integration devin-ai-integration bot force-pushed the fix/regimen-pluralization branch from 7968d4e to cfcd49a Compare January 7, 2026 16:53
… pluralization

- Replace inflection package with inflekt@0.1.0 in graphile-simple-inflector
- Replace inflection package with inflekt@0.1.0 in graphql-codegen
- Simplify pluralize.ts to re-export from inflekt (includes Latin suffix overrides)
- Update all inflection function calls to use direct imports from inflekt
@devin-ai-integration devin-ai-integration bot changed the title fix(inflection): add special case for 'regimen' pluralization fix(inflection): use inflekt package for PostGraphile-compatible pluralization Jan 7, 2026
@pyramation pyramation merged commit effae12 into main Jan 7, 2026
36 checks passed
@pyramation pyramation deleted the fix/regimen-pluralization branch January 7, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants