Repository navigation
fix(builder): stop warning about optional enum arguments as unsupported unions - #119
Open
ckhatton-pvfscaffolding wants to merge 1 commit into
Conversation
…ed unions An optional argument such as `category?: 'people' | 'company' | 'operational'` reaches makeReferenceSchema as that union plus undefined. isPrimitiveUnion rejects it because of the undefined member, so the inputs branch removes null and undefined and then warns "Union types in input fields are not supported yet", because the result is still a union, without checking that it is now an enum. The generated enum was already correct, so only the warning was wrong. The branch now leaves enum-like unions to recLoop, which registers them through its enum branch, as it does for a non-optional enum argument.
🦋 Changeset detectedLatest commit: 6715a18 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
An optional enum-like argument logs a warning on every schema build, although the schema it generates is correct. In our API:
The built schema still has the full enum, so nothing is actually narrowed to the first type:
Cause
In
makeReferenceSchema, an optional argument's type is the literal union plusundefined.isPrimitiveUnionrequires every member to be a literal, so it rejects the type and the inputs branch takes over. That branch removesnullandundefinedwithgetNonNullableType(), sees that the result is still a union, and warns, without checking that the result is now an enum.Fix
The inputs branch no longer warns when the type left after removing
nullandundefinedis a primitive union.recLoopreceives that union and registers it through its existing enum branch, which is how a non-optional enum argument (for examplestate: 'Open' | 'Closed' = 'Open') is already handled, so the generated schema is unchanged. Unions of object types still warn as before.The same code is in
packages/pylon/src/cli/builder/schema/schema-parser.tsonfeat/v3-fullstack. I'm happy to make the same change there.Testing
I built a small entry file with
SchemaBuilderfrom this branch and frommain(TypeScript 5.9.3). Its query arguments, and whether each warns:maincategory?: CompanyActivityCategorycategory?: CompanyActivityCategory | nullstate: 'Open' | 'Closed' = 'Open'flag?: booleaninput?: {a: string} | {b: number}The generated SDL is identical on both, with
category: CompanyActivityCategoryInputand the enum holding all three values. The only warning left is the object union's, which is a real union input.🤖 Generated with Claude Code