Skip to content

Commit 50c0036

Browse files
committed
feat: implement nullish
1 parent 706996a commit 50c0036

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/valibot/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ function generateFieldTypeValibotSchema(config: ValidationSchemaPluginConfig, vi
7878

7979
if (isNonNullType(parentType))
8080
return gen;
81+
82+
return `v.nullish(${gen})`;
8183
}
8284
console.warn('unhandled type:', type);
8385
return '';

tests/valibot.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,33 @@ describe('valibot', () => {
2929
},
3030
},
3131
],
32+
[
33+
'nullish',
34+
{
35+
textSchema: /* GraphQL */ `
36+
input PrimitiveInput {
37+
a: ID
38+
b: String
39+
c: Boolean
40+
d: Int
41+
e: Float
42+
z: String! # no defined check
43+
}
44+
`,
45+
wantContains: [
46+
'export function PrimitiveInputSchema()',
47+
// alphabet order
48+
'a: v.nullish(v.string()),',
49+
'b: v.nullish(v.string()),',
50+
'c: v.nullish(v.boolean()),',
51+
'd: v.nullish(v.number()),',
52+
'e: v.nullish(v.number()),',
53+
],
54+
scalars: {
55+
ID: 'string',
56+
},
57+
},
58+
],
3259
])('%s', async (_, { textSchema, wantContains, scalars }) => {
3360
const schema = buildSchema(textSchema);
3461
const result = await plugin(schema, [], { schema: 'valibot', scalars }, {});

0 commit comments

Comments
 (0)