Repository navigation
Use codegen on non-input types #20
Description
Activity
@willd-i2o I'm just curious.
How do you think the usage if available code generation for type too.I use apollo client alongside graphql-codegen
My form state is populated with data fromuseQuery, these queries utilise thetypeobjects defined in the schema, so therefore my form state is typed against thesetypeobjects.
My validation schema has to match the form state, since I'm running the validation schema via the zod resolver forreact-hook-form.
Theinputtypes are only used when I'm submitting the form and transforming my form state data into a mutation input type. Theinputtypes don't match 1-to-1 with thetypetypes used in the query, so the codegen producing validation schema's for myinputtypes doesn't help me with constructing a validation schema for my form.@willd-i2o Thanks for your explanation.
I want to confirm my understanding is correct. for example, there is a schema.type Human { name: String! age: Int! } input HumanInput { name: String! age: Int! }
Then you want to validate only for
type Human. and convert any users who have been inputtedtype Humantoinput HumanInputwhen submitting to mutation, right?Yeah that sounds about right
@willd-i2o Thanks. Don't you use fragment also?
I think this a little bit difficult.I think I could do what I would like to do without the codegen supporting fragments, but not entirely sure.
@willd-i2o I'm sorry.
After due consideration, I did not feel this desperately needed to be addressed. If there are requests from others, I will revisit this issue.
Interest here
I use Zod to validate data from my database and other sources as well. Sure that incoming data should be in the model you expect. Of course, corrupted data or a service that broke their API contract would then cause errors in your app.
I can write my own Zod schemas, of course. But I have to define my outgoing type anyway in graphQL.
Let's take this example:type User { id: ID! email: String! disabled: Boolean createdAt: String updatedAt: String } input NewUser { id: ID! email: String! } type Query { user(id: ID!): User }
At some point I am going to assemble that User JSON for my
user()resolver. Let's say I am fetching the data from something like Firebase Firestore. Well, Firestore give youanyas the base type. Sure, I can cast it in a few ways - but if I don't actually validate that data - it might not be valid.If I can auto-generate zod types from the graphql types, then I can further
pick,omit,extend, etc... the zod schema for my DB.
It seems that with the current version of the plugin, validation schemas are only generated for graphql
inputtypes found in the schema. i was wondering if it would be possible to add an option to the plugin to generate validation schemas for graphqltypeas well asinput?