Skip to content

fix(builder): stop warning about optional enum arguments as unsupported unions - #119

Open
ckhatton-pvfscaffolding wants to merge 1 commit into
getcronit:mainfrom
ckhatton-pvfscaffolding:fix/optional-enum-input-warning
Open

ckhatton-pvfscaffolding wants to merge 1 commit into
getcronit:mainfrom
ckhatton-pvfscaffolding:fix/optional-enum-input-warning

Conversation

@ckhatton-pvfscaffolding

Copy link
Copy Markdown
Contributor

Problem

An optional enum-like argument logs a warning on every schema build, although the schema it generates is correct. In our API:

export type CompanyActivityCategory = 'people' | 'company' | 'operational'

async staffGetActivity(
  companyId: number,
  page: number = 1,
  pageSize: number = 50,
  category?: CompanyActivityCategory
)
WARN  Warning: Union types in input fields are not supported yet. Defaulting to the first type (CompanyActivityCategory) at path: staffCompanyGetActivity > category

The built schema still has the full enum, so nothing is actually narrowed to the first type:

staffCompanyGetActivity(companyId: Number!, page: Number, pageSize: Number, category: CompanyActivityCategoryInput): StaffCompanyGetActivity!

enum CompanyActivityCategoryInput {
	people
	company
	operational
}

Cause

In makeReferenceSchema, an optional argument's type is the literal union plus undefined. isPrimitiveUnion requires every member to be a literal, so it rejects the type and the inputs branch takes over. That branch removes null and undefined with getNonNullableType(), 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 null and undefined is a primitive union. recLoop receives that union and registers it through its existing enum branch, which is how a non-optional enum argument (for example state: '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.ts on feat/v3-fullstack. I'm happy to make the same change there.

Testing

I built a small entry file with SchemaBuilder from this branch and from main (TypeScript 5.9.3). Its query arguments, and whether each warns:

Argument Warns on main Warns on this branch
category?: CompanyActivityCategory yes no
category?: CompanyActivityCategory | null yes no
state: 'Open' | 'Closed' = 'Open' no no
flag?: boolean no no
input?: {a: string} | {b: number} yes yes

The generated SDL is identical on both, with category: CompanyActivityCategoryInput and 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

…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-bot

changeset-bot Bot commented Nov 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6715a18

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@getcronit/pylon-builder Patch

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

No deployments
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