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
fix: batching with zod .optional()
input
#669
Conversation
This pull request is being automatically deployed with Vercel (learn more). www – ./www🔍 Inspect: https://vercel.com/trpc/www/EuKCQujsNkMFUEYtU7NtUU38uayD todomvc – ./examples/next-prisma-todomvc🔍 Inspect: https://vercel.com/trpc/todomvc/5EDB1nCkpzGnJJHsyj6bdJdohQaz |
[undefined]
gives [null]
- solve by extra input pass[undefined]
gives [null]
I've just checked the PR. I am not sure if I like the hack, but it should do the job. But... I am not sure if we should merge this. If we expect the library to always parse values correctly, we should set a transformer (SuperJSON or something similar) by default and not just handle one specific edge case. But if the library by default uses |
I understand your point of view, I just think this is a very common edge-case, especially since I want to enable batching per default (#160). I don't wanna add transformers as default as they add a perf hit and everyone don't benefit from having them. At least not superjson, as it's slow. I wish |
I see. So it is probably worth handling this specific case. Then I have only one more concern: Are
I like the idea of throwing on Dates/Maps/Sets/... by default. The only thing I would suggest then is to do a little research, what kind of problems JSON.stringify/parse has, so we are not only addressing a few but all (or at least many) of them. |
One more question: Couldn't we solve this client-side? So if the input value is |
Good idea, but it would break this code instead export const appRouter = createRouter()
.query('hello', {
input: z.string().min(1).optional(),
resolve: ({ input, ctx }) => {
return `hello ${input ?? 'world'}`;
},
})
// [...]
await client.query('hello'); // will throw |
But why? |
@all-contributors add @simonedelmann for reviews |
I've put up a pull request to add @simonedelmann! 🎉 |
- Reduce `TRPCError`s - `METHOD_NOT_FOUND` removed & `PATH_NOT_FOUND` renamed to `NOT_FOUND` (closes #733) - Align input and output serialization (closes #746) - Remove deprecated `httpErrors`-helper - Remove support for `?input` to be an array - now assuming a `Record<number, unknown>`-style dict (changed with backward compat in #669) - Remove support for `POST` calls being `{ input: x }` (originally from #671)
JSON.stringify([undefined])
===[null]
.optional()
zod schemas as it expects an object orundefined
, notnull
fixed by ugly hack that runs validator twice when it fails if the raw input was=== null
.fixed by @simonedelmann's idea