Skip to content

Commit 248a35d

Browse files
committed
feat: support notAllowEmptyString issue #386
1 parent 3b0c467 commit 248a35d

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/valibot/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,13 @@ function generateNameNodeValibotSchema(config: ValidationSchemaPluginConfig, vis
142142
case 'InputObjectTypeDefinition':
143143
case 'ObjectTypeDefinition':
144144
case 'UnionTypeDefinition':
145-
throw new Error('not implemented');
145+
// using switch-case rather than if-else to allow for future expansion
146+
switch (config.validationSchemaExportType) {
147+
case 'const':
148+
case 'function':
149+
default:
150+
return `${converter.convertName()}Schema()`;
151+
}
146152
default:
147153
if (converter?.targetKind)
148154
console.warn('Unknown targetKind', converter?.targetKind);

tests/valibot.spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,44 @@ describe('valibot', () => {
246246
"
247247
`)
248248
});
249+
250+
it('with notAllowEmptyString issue #386', async () => {
251+
const schema = buildSchema(/* GraphQL */ `
252+
input InputOne {
253+
field: InputNested!
254+
}
255+
256+
input InputNested {
257+
field: String!
258+
}
259+
`);
260+
const result = await plugin(
261+
schema,
262+
[],
263+
{
264+
schema: 'valibot',
265+
notAllowEmptyString: true,
266+
scalars: {
267+
ID: 'string',
268+
},
269+
},
270+
{},
271+
);
272+
expect(result.content).toMatchInlineSnapshot(`
273+
"
274+
275+
export function InputOneSchema() {
276+
return v.object({
277+
field: InputNestedSchema()
278+
})
279+
}
280+
281+
export function InputNestedSchema() {
282+
return v.object({
283+
field: v.string([v.minLength(1)])
284+
})
285+
}
286+
"
287+
`);
288+
});
249289
})

0 commit comments

Comments
 (0)