Zod type provider causing validation error #1213
officialjs
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all just a small warning on an issue that I picked up using Mercurius in my current project.
When using
fastify-type-provider-zodas a global type provider in Fastify, Mercurius routes (like /graphql) fail during the pre-validation phase. This happens because the Zod type provider attempts to validate the incoming GraphQL request body against a non-existent Zod schema, resulting in a Zod internal error: TypeError: Cannot read properties of undefined (reading 'run').This error occurs even if no Zod validation is explicitly defined for the GraphQL route, as the global provider attempts to parse the request context by default. Frustratingly enough no error is bubbling up that helps to debug this..
The solution is thankfully very simple. You just have to override the compilers for the Mercurius route using
additionalRouteOptionsto bypass the Zod validation logic.Hope this helps ✌️
Beta Was this translation helpful? Give feedback.
All reactions