Closed sschneider-ihre-pvs closed 2 years ago
There are only query examples, please add one for Mutations like create, update, delete.
You can simply write Mutation
instead of Query
like MutationWithZod
. The subscription is also the same. They have very same overloads for corresponding decorator overloads.
But what about if none nullable competes with zod required?
so if you have a field that is required for a database operation maybe even a primary key and it is allowed to be nullable, so in the graphql schema it needs to be nullable also. but in the zod schema either default null or required
so if you have a field that is required for a database operation maybe even a primary key and it is allowed to be nullable, so in the graphql schema it needs to be nullable also. but in the zod schema either default null or required
Could you please provide an example of what you want to mention? Because I think I need to get this well, it is not clear for me yet.
id primary nullable | value |
---|---|
[null] | "----" |
1 | "Hello World" |
The default values are also applied if you provide the default with the zod. For example:
const Scheme = z.object({
id: z.string().optional().default('----')
}).describe('DbTable: Example')
With this scheme, it is expected to have the following GraphQL scheme:
"""Example"""
model DbTable {
id: String
}
As you see the id
field is now nullable
.
So you apply this scheme object to any method like:
class ResolverClass {
@MutationWithZod(Scheme)
method() {
// actual logic here
}
}
Now as you have used .default(...)
call on the zod scheme above, now your field/property will have its default value. Therefore if nothing is given from the client, the default value will be used.
I hope this answers your question @sschneider-ihre-pvs.
There are only query examples, please add one for Mutations like create, update, delete.