Skip to content

refactor: centralize GSI accessor helper (follow-up to #3505)#3511

Draft
Simone319 wants to merge 1 commit into
mainfrom
refactor/centralize-gsi-accessor
Draft

refactor: centralize GSI accessor helper (follow-up to #3505)#3511
Simone319 wants to merge 1 commit into
mainfrom
refactor/centralize-gsi-accessor

Conversation

@Simone319

Copy link
Copy Markdown
Contributor

What

Centralizes the dual-path DynamoDB GSI accessor introduced in #3505 into a single shared helper and points all three consumers at it.

aws-cdk-lib 2.252/2.260 renamed the DynamoDB L2 Table internal globalSecondaryIndexes array to _globalSecondaryIndexes (now an ArrayBox). #3505 landed the fallback expression table['_globalSecondaryIndexes'] ?? table.globalSecondaryIndexes, but the identical accessor ended up duplicated in 3 packages.

New export in @aws-amplify/graphql-transformer-core (src/utils/schema-utils.ts):

export const getGlobalSecondaryIndexes = (table: any): any =>
  table['_globalSecondaryIndexes'] ?? table.globalSecondaryIndexes;

Why

Per sarayev's review suggestion (idea B) on #3505: dedupe the 3× accessor so a future CDK rename is a one-line fix in one place instead of a hunt across packages.

Updated call sites (all 3)

  • packages/amplify-graphql-relational-transformer/src/resolvers.ts — removed the local getGlobalSecondaryIndexes in favor of the shared one; .some(gsi => gsi.indexName === …) logic unchanged.
  • packages/amplify-graphql-transformer-core/src/utils/schema-utils.tsgetKeySchema now calls the shared helper for the GSI array (LSI accessor left inline, out of scope).
  • packages/amplify-graphql-conversation-transformer/.../conversation-resolver-generator.ts — inline accessor replaced with the shared helper; .find(…).keySchema logic unchanged.

All three already depend on @aws-amplify/graphql-transformer-core, so no new/circular dependency is introduced.

No behavior change

This is a pure refactor + dedupe. The dual-path semantics are byte-for-byte identical — notably it does not add ?? [] or otherwise harden the accessor (that hardening is a separate decision). Return type kept as any to match exactly what the call sites rely on (.find(...).keySchema without a null-guard).

It also does not remove the private-field dependency: a truly private-free accessor would require a managed-vs-standard-table branch, which is deliberately out of scope here.

Testing

  • graphql-transformer-core unit tests: 92 passed
  • graphql-relational-transformer unit tests: 194 passed
  • graphql-conversation-transformer unit tests: 25 passed
  • All 3 packages compile (tsc), prettier applied, API.md regenerated (only the new export added).

Follow-up to #3505.

Dedupe the aws-cdk-lib 2.252/2.260 _globalSecondaryIndexes fallback across 3
packages; no behavior change [follow-up to #3505]

Extracts the dual-path accessor `table['_globalSecondaryIndexes'] ??
table.globalSecondaryIndexes` into a single exported helper
`getGlobalSecondaryIndexes` in @aws-amplify/graphql-transformer-core and points
all three call sites at it (relational-transformer resolvers, transformer-core
schema-utils getKeySchema, conversation-transformer resolver generator).
Identical dual-path semantics preserved.
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.

1 participant