Skip to content

Support valibot (lightweight version of zod) #577

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

Closed
lopezjurip opened this issue Mar 5, 2024 · 6 comments
Closed

Support valibot (lightweight version of zod) #577

lopezjurip opened this issue Mar 5, 2024 · 6 comments

Comments

@lopezjurip
Copy link

Consider Valibot over Zod: achieves lighter bundles & modularity, enhancing performance & flexibility.

https://bundlephobia.com/package/zod@3.22.4
It's 57KB gziped.

See: https://github.com/fabian-hiller/valibot

@Code-Hex
Copy link
Owner

Code-Hex commented Apr 6, 2024

@lopezjurip Hi!
I agree adding valibot support to this plugin.
Could you send me PR for this? Thanks!

@MH4GF
Copy link
Contributor

MH4GF commented Apr 10, 2024

@Code-Hex @lopezjurip
I am a fan of graphql-codegen-typescript-validation-schema and valibot. I would like to submit a PR because I would like to use these two in a project I am working on! May I assign this issue to me?

@Code-Hex
Copy link
Owner

@MH4GF Sure! I'm looking forward your PR!

@MH4GF
Copy link
Contributor

MH4GF commented Apr 11, 2024

@Code-Hex Please let me confirm about the definedNonNullAny that is zod's temporary hack.

Surprisingly, valibot seems to compile the following code:

import * as v from 'valibot';

type A = {
  foo: any;
};

function AParser(): v.ObjectSchema<A, undefined> {
  return v.object({
    foo: v.any()
  });
}

const result = v.safeParse(AParser(), {
  foo: 'bar',
});

console.log(result);

type InferA = v.InferOutput<ReturnType<typeof AParser>>;
// =>
// type InferA = {
//   foo: any;
// }

playground: https://valibot.dev/playground/?code=JYWwDg9gTgLgBAKjgQwM5wG5wGZQiOAcg2QBtgAjCGQgbgCh6YBPMAUzgEE4BeOAb3pwcECAC4UAO2YMAvg3rYArpIDGMYBElcACsiio2UABQBKCRgB0AeQoArNuoDKqgBZsQyADycANHBUAEzZsYEk2QIA+ASE4KDYYJShtKwh7RxhjQWFhbFELS2RpM1jZUzlGFnY4AElJbCNuPis6hqhrJRgwTq8AJQSkyQAVVjYvKrYIbF19QyhIyIVVLVR4eNQlUnhmy1RkBr0DNmNOQ7mzf2yRcSIKfUJfejKllYhSNktSCABzY3XNmDlIA

So, is the schema to be generated correct with the intention of v.object({ foo: v.any() }) ?

ref: colinhacks/zod#951

@Code-Hex
Copy link
Owner

@MH4GF Thank you for your question.

In zod, I employed a hack to define a schema for the any type that excludes undefined and null. I hope to create something that aligns with this intention.

Does this answer your question?

@Code-Hex
Copy link
Owner

@MH4GF Big Thanks!!

I just published valibot support version!
https://github.com/Code-Hex/graphql-codegen-typescript-validation-schema/releases/tag/v0.15.0

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 a pull request may close this issue.

3 participants