-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
[Feature request] support object in directive field to method params #360
Comments
input ComponentInput {
type: ButtonComponentType!
name: String! @required(msg: "Hello")
event: EventInput
child: ComponentInput
childrens: [ComponentInput]
} Then generated: export function ComponentInputSchema(): yup.ObjectSchema<ComponentInput> {
return yup.object({
child: yup.lazy(() => ComponentInputSchema()).optional(),
childrens: yup.array(yup.lazy(() => ComponentInputSchema())).defined().nullable().optional(),
event: yup.lazy(() => EventInputSchema()).optional(),
name: yup.string().defined().nonNullable().required("Hello"), // This one
type: ButtonComponentTypeSchema.nonNullable()
})
} This directive works even if it is not defined as a GraphQL schema. Or does the request want to assign default error messages? (to |
yeah the idea is to be able to define the error message for those in my example which I can already do in yup but can't in zod because they use object parameter and the only thing we can use as param from my understanding are string and regexp z.string().string({required_error: 'The field is required.'}) Additionally we can't reuse the same method in zod oposite to yup. this is valid in yup: yup.number().defined().defined().defined().defined() but invalid in zod. |
Ah, I think I understand. config:
required: $1
errorMessage: $1
applyTo: defined # will be generated method GraphQL Schema looks like this. input ComponentInput {
type: ButtonComponentType!
name: String! @required(errorMessage: "Hello")
event: EventInput
child: ComponentInput
childrens: [ComponentInput]
} The expected generation is export function ComponentInputSchema(): yup.ObjectSchema<ComponentInput> {
return yup.object({
child: yup.lazy(() => ComponentInputSchema()).optional(),
childrens: yup.array(yup.lazy(() => ComponentInputSchema())).defined().nullable().optional(),
event: yup.lazy(() => EventInputSchema()).optional(),
name: yup.string().defined("Hello").nonNullable(), // this one
type: ButtonComponentTypeSchema.nonNullable()
})
} However, this method is not very intuitive for first-time users. |
Yes something like this would works I think |
would be nice to support object in directive parsing.
Yup currently allow you to define a specific error message string quite easily for required.
sadly this seems to be the equivalent in zod and it does not work. If we put the content between quotes we end up with this
z.string().string("{required_error: 'The field is required.'}")
.This is having two issues:
Had a quick look but sadly my understanding of the lib is quite small so haven't been able to add that feature.
The text was updated successfully, but these errors were encountered: