Skip to content

feat: minimal implementation to support valibot #667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: support nullish
  • Loading branch information
MH4GF committed May 29, 2024
commit 6cead63b7a0409ce4d9ca530f06b61dc4b2c3b5b
2 changes: 2 additions & 0 deletions src/valibot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ function generateFieldTypeValibotSchema(config: ValidationSchemaPluginConfig, vi

if (isNonNullType(parentType))
return gen;

return `v.nullish(${gen})`;
}
console.warn('unhandled type:', type);
return '';
Expand Down
30 changes: 30 additions & 0 deletions tests/valibot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,34 @@ describe('valibot', () => {
"
`);
})
it('nullish', async () => {
const schema = buildSchema(/* GraphQL */ `
input PrimitiveInput {
a: ID
b: String
c: Boolean
d: Int
e: Float
z: String! # no defined check
}
`);
const scalars = {
ID: 'string',
}
const result = await plugin(schema, [], { schema: 'valibot', scalars }, {});
expect(result.content).toMatchInlineSnapshot(`
"
export function PrimitiveInputSchema(): v.GenericSchema<PrimitiveInput> {
return v.object({
a: v.nullish(v.string()),
b: v.nullish(v.string()),
c: v.nullish(v.boolean()),
d: v.nullish(v.number()),
e: v.nullish(v.number()),
z: v.string()
})
}
"
`);
})
})