Skip to content

Conversation

@Shubh-Raj
Copy link

Closes #194

This PR fixes the bug where optional scalar fields lose their optional modifier (?) when generating TypeScript code.

Changes

  • Modified visit() in lib/codegen/fromcto/typescript/typescriptvisitor.js to pass forceOptional via parameters when handling scalar fields, avoiding mutation of the shared scalar descriptor
  • Updated visitField() to honor parameters.forceOptional when determining if a field should have the ? modifier
  • Added unit test to verify that optional scalar fields correctly propagate their optional status via parameters

Flags

  • None - this is a targeted bug fix with no breaking changes
  • All 567 existing tests pass with 99%+ coverage

Screenshots or Video

Before fix: nickname: string; (missing ? for optional scalar)

After fix: nickname?: string; (correctly includes ?)

Related Issues

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to main from fork:fix/scalar-optional-typescript

When generating TypeScript code, optional scalar fields were losing
their optional modifier. This fix propagates the optional property
from the parent field via the forceOptional parameter, avoiding
mutation of the shared scalar descriptor.

Signed-off-by: Shubh-Raj <shubhraj625@gmail.com>
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.

fix(typescript): optional scalar fields lose their optional modifier

1 participant