Skip to content

refactor: consolidate duplicated name-matching and case helpers via inflekt@0.5.0#896

Merged
pyramation merged 11 commits intomainfrom
feat/v5-fixes-relation-query-naming
Mar 26, 2026
Merged

refactor: consolidate duplicated name-matching and case helpers via inflekt@0.5.0#896
pyramation merged 11 commits intomainfrom
feat/v5-fixes-relation-query-naming

Conversation

@pyramation
Copy link
Copy Markdown
Contributor

@pyramation pyramation commented Mar 25, 2026

Summary

Bumps inflekt to ^0.5.0 across graphql/query, graphql/codegen, and graphile/graphile-settings, then replaces duplicated logic with direct imports from the published package:

  • field-selector.ts / select.ts: Import fuzzyFindByName from inflekt instead of duplicating normalize + compare inline. The intermediate local name-matching.ts module (added in an earlier revision) has been deleted — inflekt is now the single source of truth.
  • codegen/utils.ts: Replaces local lcFirst, ucFirst, toCamelCase, toPascalCase, toScreamingSnake function bodies with re-exports from inflekt.
  • relation-meta-builders.ts: Minor cleanup — extracts repeated relation.remoteResource?.codec into a local remoteCodec variable.

Companion PR: constructive-io/dev-utils#71 (adds these utilities to inflekt).

This is not a pure refactor. Two behavioral changes are included:

  1. select.tsfindRelatedTable: Previously did exact match only. Now uses fuzzy matching (case-insensitive, underscore-stripping, trailing-'s' tolerance). This means relation lookups that previously returned null may now resolve correctly when codec names differ in case/pluralization from table type names.

  2. field-selector.tsgetRelatedTableScalarFields: When no related table is found, the fallback changed from return {} to return { __typename: true } so generated queries remain valid (connection nodes require at least one subfield).

Updates since last revision

  • Merged latest main into the branch to fix a CI lockfile failure (ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY for inflekt@0.3.3). The lockfile now includes both inflekt@0.3.3 (transitive, from other packages on main) and inflekt@0.5.0.

Review & Testing Checklist for Human

  • Verify fuzzy matching in select.ts doesn't produce false-positive table matches. The new findRelatedTable now fuzzy-matches where it previously only did exact match. If two tables have names that normalize to the same base (e.g., hypothetical "Status" vs "Statuses" table), this could match the wrong one. Scan your schema for any ambiguous table names.
  • Validate the { __typename: true } fallback in field-selector.ts line ~307. Previously returned {} when the related table wasn't found. Confirm that __typename is acceptable as a minimum subfield selection for connection nodes in your PostGraphile setup.
  • Confirm inflekt@0.5.0 case helpers are equivalent to the removed local implementations. codegen/utils.ts previously defined toCamelCase, toPascalCase, toScreamingSnake locally. These are now re-exported from inflekt. Verify the inflekt implementations match expected behavior (especially edge cases like leading underscores, consecutive capitals, etc.).
  • Test with a real schema that has relation fields — verify that relation subfield selections still generate correct queries, especially for tables with snake_case or plural codec names.

Notes

  • The pnpm-lock.yaml diff is large due to lockfile format changes and a merge with main; the only meaningful dependency change is inflekt 0.3.3 → 0.5.0. The lockfile retains a inflekt@0.3.3 snapshot because it is still transitively reachable from main.
  • fuzzyFindByName singularizes the target name but not the item names. Looking up "shipments" will find "Shipment", but "Shipment" will not find "Shipments". Verify this matches the actual direction of lookups (codec name → table type name).

Link to Devin session: https://app.devin.ai/sessions/e3dd5ed7753043bd8d2166793364cd42
Requested by: @pyramation

yyyyaaa and others added 8 commits March 25, 2026 10:07
Reverts the PascalCase inflection applied in 6be9101. Relation target
names in _meta (type, junctionTable.name, rightTable.name,
referencedBy.name, references.name) now consistently use the raw
PostGraphile codec name (e.g. post_tag, tag) rather than inflected
GraphQL type names (PostTag, Tag).

This keeps naming uniform across the entire _meta schema and ensures
the dashboard phantom-column junction filter can directly compare
junctionTable.name from manyToMany entries against referencedBy.name
from hasMany entries without any case normalisation.
Extract duplicated fuzzy table-name matching logic from field-selector.ts
and select.ts into a shared name-matching.ts module. Both files now import
fuzzyFindByName from the shared utility instead of duplicating the normalize +
compare logic inline.

Also adds NOTE comments to codegen/utils.ts indicating that lcFirst, ucFirst,
toCamelCase, toPascalCase, and toScreamingSnake can be replaced with re-exports
from inflekt once version 0.4.0 is published (see dev-utils PR #71).
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

- 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)
@devin-ai-integration devin-ai-integration Bot changed the title refactor: consolidate duplicated name-matching into shared utility refactor: consolidate duplicated name-matching and case helpers via inflekt@0.5.0 Mar 26, 2026
@pyramation pyramation merged commit 7bd2b6e into main Mar 26, 2026
44 checks passed
@pyramation pyramation deleted the feat/v5-fixes-relation-query-naming branch March 26, 2026 02:01
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.

2 participants