Skip to content

fix(valibot): apply directives to list fields instead of their items - #1583

Open
Kretiss wants to merge 1 commit into
Code-Hex:mainfrom
Kretiss:fix/valibot-list-directives
Open

Kretiss wants to merge 1 commit into
Code-Hex:mainfrom
Kretiss:fix/valibot-list-directives

Conversation

@Kretiss

@Kretiss Kretiss commented Sep 23, 2026

Copy link
Copy Markdown

Follow-up to #489 / #1423, which fixed this for the Zod generators.

The valibot generator still applies a list field's directives to each item, so a length constraint on an array
limits every element instead of the array:

input UserCreateInput {
  tags: [String!]! @constraint(minLength: 1, maxLength: 10)
}
// before
tags: v.array(v.pipe(v.string(), v.minLength(1), v.maxLength(10)))
// after
tags: v.pipe(v.array(v.string()), v.minLength(1), v.maxLength(10))

This ports the isRoot handling of generateFieldTypeZodSchema to generateFieldTypeValibotSchema: the directives
go on the outermost v.array(...) of the field (non-null and nullable lists alike), and items get none. Scalar fields
are unchanged, and notAllowEmptyString still applies to string items.

The it.todo('list field') under "issues #19" is now a real test covering [String!]!, [String!] and a nested
[[String!]!]!.

🤖 Generated with Claude Code

Ports the isRoot handling of the Zod generators (Code-Hex#1423) to valibot, so a
list field's directives pipe the outermost v.array(...) and its items get
none. Replaces the list field todo with a test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.

1 participant