Open
Description
When array elements are not nullable, the array validation constraints are applied not to array, but each element
I've modified an existing zod testcase which now fails to visualize this problem:
it('list field non-null', async () => {
const schema = buildSchema(/* GraphQL */ `
input UserCreateInput {
profile: [String!]! @constraint(minLength: 1, maxLength: 5000)
}
directive @constraint(minLength: Int!, maxLength: Int!) on INPUT_FIELD_DEFINITION
`);
const result = await plugin(
schema,
[],
{
schema: 'zod',
directives: {
constraint: {
minLength: ['min', '$1', 'Please input more than $1'],
maxLength: ['max', '$1', 'Please input less than $1'],
},
},
},
{}
);
const wantContains = [
'export function UserCreateInputSchema(): z.ZodObject<Properties<UserCreateInput>>',
'profile: z.array(z.string()).min(1, "Please input more than 1").max(5000, "Please input less than 5000")',
];
for (const wantContain of wantContains) {
expect(result.content).toContain(wantContain);
}
});
Metadata
Metadata
Assignees
Labels
No labels