Skip to content

Add type-usage and reachability analysis module#71

Draft
FionaBronwen wants to merge 1 commit intofionabronwen/graphql-migrate-test-hostfrom
fionabronwen/graphql-type-usage
Draft

Add type-usage and reachability analysis module#71
FionaBronwen wants to merge 1 commit intofionabronwen/graphql-migrate-test-hostfrom
fionabronwen/graphql-type-usage

Conversation

@FionaBronwen
Copy link

Summary

  • Adds src/type-usage.ts — determines which types should be included in the emitted GraphQL schema based upon reachability and classifies them as Input, Output, or both based on operation signatures
  • Adds test/type-usage.test.ts — 15 unit tests
  • Removes src/visibility-usage.ts — previous approach

This approach implements a custom usage tracker instead of the TypeSpec compiler's resolveUsages because we need to account for custom scalars. resolveUsages skips scalars and therefore, any custom scalar in the schema would be automatically considered "unreachable".

Test plan

  • Added 15 unit tests covering reachability, usage classification, circular references, and omitUnreachableTypes behavior
  • All 117 tests pass, build clean

resolveTypeUsage walks all operations in a namespace tree and tracks
which types are reachable from operation parameters (Input) vs return
types (Output). Handles circular references, array elements, base
models, union variants, enums, and scalars.

When omitUnreachableTypes is false, all declared types are marked
reachable without adding spurious Input/Output flags.

Includes 13 unit tests covering all reachability scenarios.
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