Closed exKAZUu closed 2 years ago
I have another but a related question.
Since the file path of the auth validation is app/auth/validations.ts
, I suspect we should move validation.ts
from app/pages/questions/validations.ts
to app/questions/validations.ts
. (Actually, I tried, but the behavior didn't change)
Hey! Thanks for reporting this.
As for the first question — yes, the validators don't work when exported from mutations/
or queries/
folders. That's because code in those folders can only run on the server, and secondary imports are undefined on the frontend. Here's more: https://github.com/blitz-js/blitz/issues/2754. That's why it's necessary to move it to a separate file: https://blitzjs.com/docs/tutorial#adding-choices-to-the-question-form (but that code doesn't seem to work either?)
Since we already have the issue for the secondary imports problem, one thing that we should do is update the tutorial. I'll move this issue to our docs repo.
As for the second question — the location shouldn't matter — once the code in the validations.ts
is correct it should be fine. However, we can unify it and have it in a similar way as for auth
. That also requires a change in the tutorial.
We also have this issue: https://github.com/blitz-js/blitz/issues/2815 to put validators in a separate file out of the box.
Thank you for the explanation, I understand :bow:
I also feel it's good to mention about import statements for mutations/
or queries/
in the tutorial (though I understand maintaining documents is a hard task.)
Yeah, we can definitely mention it!
@exKAZUu I added a mention here 38044d2. If that solves it, feel free to close this issue
What is the problem?
The tutorial shows the following code, but client validation seems not working.
For example, if we change the definition of
CreateQuestion
as follows:I expect we cannot enter a non-email string in a question text, but we can do and we will get the following error from a SERVER (not a client).
If we move the definition of
CreateQuestion
fromapp/questions/mutations/createQuestion.ts
toapp/pages/questions/validations.ts
as follows, then client validation works well.Paste all your error logs here:
Please see the above screenshot.
Paste all relevant code snippets here:
Please see the above code snippets.
What are detailed steps to reproduce this?
CreateQuestion
(text: z.string()
->text: z.string().email()
)Run
blitz -v
and paste the output here:Please include below any other applicable logs and screenshots that show your problem:
Please see the above screenshot.