-
-
Notifications
You must be signed in to change notification settings - Fork 51
implementation with myzod #25
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
Comments
Thanks your feedback. yup and zod provide it. So we can modify schema if generated a little bit different. (I announced tips here. https://github.com/Code-Hex/graphql-codegen-typescript-validation-schema/tree/main/example/zod) Isn't this inconvenient? |
I haven't seen where you use .extend feature for zod and besides, the generated output is there to be modified accordingly. I don't see why this should be an obstacle for supporting myzod. Moreover, you can use .and or Type.map to transform/modify the schema const AttributeInputSchemaWithCUID = AttributeInputSchema().extend({
key: z.string().cuid(),
}) Can be written as: const withCUID = myzod.object({ key: z.string() .withPredicate(CUID.isValid, 'must be a valid CUID')
.map(value => new CUID(value)),
});
const AttributeInputSchemaWithCUID = AttributeInputSchema().and(withCUID) |
So what do you say, does my PR gets merged or what? 93/93 test passed |
@Parables Amazing your work! Thanks a lot. I need a little bit fix documents for myzod. but I can handle for it. Great job! One more! Could you fix to be valid syntax of your suggested sample code in your comment? 🙏 modified I just published https://github.com/Code-Hex/graphql-codegen-typescript-validation-schema/releases/tag/v0.5.0 |
Your code is broken on a few points. I need to fix them, |
I am really grateful for accepting my PR.
Please let me know what I have to do and I will do it ASAP |
@Parables Sorry again. One more! Could you fix to be valid syntax of your suggested sample code in your comment? 🙏 Around |
import cuid from "cuid";
import myzod, { Infer } from "myzod";
import isEmail from "validator/es/lib/isEmail";
import isStrongPassword from "validator/es/lib/isStrongPassword";
const ProfileInputSchema = myzod
.object({
username: myzod.string().min(3),
email: myzod
.string()
.withPredicate((value) => isEmail(value), "Email must be a valid email"),
password: myzod
.string()
.min(8)
.withPredicate(isStrongPassword, "Password is too weak"),
confirmedPassword: myzod.string()
})
.withPredicate(
(value) => value.password === value.confirmedPassword,
"password and confirmed do not match"
);
const ProfileSchema = myzod.pick(ProfileInputSchema, ["username", "email"]);
const WithCUID = myzod.object({
id: myzod
.string()
.optional()
.map((value) => value ?? cuid())
});
const ProfileSchemaWithCuid = ProfileSchema.and(WithCUID);
type Profile = Infer<typeof ProfileSchemaWithCuid>;
const result = ProfileSchemaWithCuid.try({
username: "Parables",
email: "[email protected]"
});
if (result instanceof myzod.ValidationError) {
console.log("Invalid format");
} else {
console.log("Result: ", result);
}
// console.log("Shape of ProfileSchemaWithCuid: ", ProfileSchemaWithCuid.shape()); |
checkout a live demo https://codesandbox.io/s/extend-myzod-schema-giwqf7 |
Hope it helps... let me know if there is anything else.... Thanks for accepting my PR once again... mean a lot to me |
Sure no problem... I actually typed that code directly in the comments 🙃
…On Sun, Apr 3, 2022, 1:05 AM Kei Kamikawa ***@***.***> wrote:
@Parables <https://github.com/Parables> Sorry again. One more!
Could you fix to be valid syntax of your suggested sample code in your
comment? 🙏
#25 (comment)
<#25 (comment)>
—
Reply to this email directly, view it on GitHub
<#25 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJDDF3SIKMTTPIOR7ZPN4MLVDDVD5ANCNFSM5SFSGYBQ>
.
You are receiving this because you were mentioned.Message ID:
<Code-Hex/graphql-codegen-typescript-validation-schema/issues/25/1086752394
@github.com>
|
I really love the plugin so much.....
Please can we have an implementation with myzod.
The text was updated successfully, but these errors were encountered: